How can I print characters like "ø", "ć", "þ" from an API response without dumping them on a file?

Viewed 21

I have a response object that has some names with those characters.

Say my response is the following:

{"data": [{"name": "Pavlovi\u0107", "team": "Br\u00F8ndby"},{"name":"J\u00f3n Dagur \u00de\u00f3rsteinsson", "team": ""}....]}

I want to print the name of each player and their team with the "correct" characters. I tried:

Attempt 1

r = response.text
print(json.dumps(r, indent=4, ensure_ascii=False)

Attempt 2

r = response.json()
for player in r['data']:
    print(player['name'] + ' | ' +  player['team'])

Both attempts end up with UnicodeEncodeError at some point.

Thanking you in advance for your guidance!

0 Answers
Related