I have a JSON object with UTF8 characters in them. When I try to print the object to the console (in Windows 8.1), it throws this error: UnicodeEncodeError: 'charmap' codec can't encode character '\u2026' in position 3706: character maps to <undefined>
because the console doesn't support display of some UTF8 characters. I checked this answer but none of the solutions work, because a JSON object cannot be encoded and decoded. How to fix encoding issues for JSON?
def getTweets(self, company):
#params
baseUrl = 'https://api.twitter.com/1.1/search/tweets.json'
values = {'q' : company, 'result_type' : 'recent', 'count' : 100}
params = urllib.parse.urlencode(values)
url = baseUrl + '?' + params
#headers
authorization = 'Bearer %s' % self.bearer
acceptEncoding = 'gzip'
headers = {'User-Agent' : self.userAgent, 'Authorization' : authorization, 'Accept-Encoding' : acceptEncoding}
req = urllib.request.Request(url, None, headers)
response = urllib.request.urlopen(req)
rawData = response.read()
decompressedData = zlib.decompress(rawData, 16+zlib.MAX_WBITS)
decompressedData = decompressedData.decode('utf-8')
#print(decompressedData)
jsonData = json.loads(decompressedData)
print(jsonData)