Broken utf-8 encoding with queries
I am using queries to fetch data from the corresponding API. The problem is that when I try to convert the response to UTF-8 it results in some broken characters like
if i use response.text
i get
response.content = {"description":"Golden Cã£o Mb Adulto 3kg F"}
If I use response.content
I get
response.content = {"description":"Golden C\xc3\xa3\xc2\xa3o Mb Adulto 3kg F"}
I have tried changing the encoding of the request with response.encoding = 'utf-8'
, response.encoding = 'latin-1'
and many others before response.text
. I tried response.decode('utf-8')
others to decode as well. In this case I{"description":"Golden Cã£o Mb Adulto 3kg F"}
I have many other things in this answer, if I use
response.text.encode('latin-1').decode('utf-8')
I can fix some of these broken qualities, but in the above example I get this error
{UnicodeDecodeError} 'utf-8' codec cannot decode bytes ...: Invalid continuation byte
I have tried many other things, but I could not fix it. I need help.
Edit: Server response headers
{
'Content-Type': 'application/json',
'Vary': 'Accept-Encoding',
'Content-Encoding': 'gzip',
'Content-Length': '1603',
'Connection': 'close'
}
For the example above, the result should be
{"description":"Golden Cão Mb Adulto 3kg F"}
EDIT: Solved It turns out the error was on the server side. When saving them, the server distorted some characters.
source to share
No one has answered this question yet
See similar questions:
or similar: