2

I am having problems with a code created in Python, and it is that when I generate some texts in json, the accents are not appreciated.

This is the code I'm using:

import requests
url = requests.get(f"https://images.habbo.com/habbo-web-news/es/production/front.json")
summary = url.json()[0]['summary']
print(summary)

This is the text that generates me:

Nos estamos preparando para esos fríos meses de invierno con unos merecidos mimos en el Onsen japonés.

I am having problems with a code created in Python, and it is that when I generate some texts in json, the accents are not appreciated.

Someone could help me?

  • The accents are there, it is in Unicode Hex form. Try the solution from this post https://stackoverflow.com/questions/6999737/convert-from-hex-character-to-unicode-character-in-python – MrDiamond Nov 22 '22 at 01:01

1 Answers1

0

JSON is always in unicode. So you want utf8 encoding everywhere.

The url you mentioned sends this (correct) header:

content-type: application/json

Here is a snippet of the content:

"content": "<h2>Invierno en el Onsen Japon&#xE9;s</h2>\r\n<p>Hey Habbo, tus p&#xED;xeles estaban rozando el estado de congelaci&#xF3;n perpetuo....

There's nothing wrong with the webserver, nor with the code you posted.

We do see some hex escapes that apparently you don't want:

  • &#xE9; é
  • &#xED; í
  • &#xF3; ó

You're unhappy with the component that introduced those hex escapes. Find it and fix it.

tl;dr: You have bad data. Fix the data, not the code you posted.

J_H
  • 17,926
  • 4
  • 24
  • 44