0

I get this error: UnicodeEncodeError: 'charmap' codec can't encode character '\u2082' in position 1088: character maps to <undefined> when I try to load a request text to JSON in python 3.9, so my code is:

rq= requests.get(url)
rqJson= json.loads(rq.text)
print(rqJson)

I'm using Windows 10 and sys.stdout.encoding is utf-8

any help with this please?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
E. Aly
  • 321
  • 4
  • 16
  • Maybe this will help: https://stackoverflow.com/questions/27092833/unicodeencodeerror-charmap-codec-cant-encode-characters – Andrej Kesely Aug 31 '21 at 22:07
  • Your terminal does not support the character. Start here: https://stackoverflow.com/questions/5419/python-unicode-and-the-windows-console/32176732#32176732 . Also, please only tag things that are relevant to the problem, not everything that you are using in the code that leads up to the problem. Here, you clearly would have a problem as long as `rqJson` contained the character in question, even if it didn't come from a web request and even if it were a single string instead of a nested structure. – Karl Knechtel Aug 31 '21 at 22:11
  • As a simpler test, try `print('\u2082')`; it should cause the same problem (in which case that should be your actual [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Karl Knechtel Aug 31 '21 at 22:13
  • Thanks @KarlKnechtel for your reply, I have actually tried to ```print('\u2082')``` in the windows terminal and it didn't cause any errors. However, when I try to print that in vscode (which is the IDE I'm using to write my code), I get the same error. So any hint what might be the problem here? – E. Aly Aug 31 '21 at 22:23
  • Your IDE does not support the character as is, presumably. Stack Overflow is not tech support. Try [researching the topic](https://duckduckgo.com/?q=vscode+can%27t+display+unicode), as is [expected](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). – Karl Knechtel Aug 31 '21 at 22:56

0 Answers0