How to resolve txt special character error

Asked

Viewed 92 times

0

I’m using the library requests and the following code in Python to take data from Receita-WS and to JSON in a TXT.

for i in lista_empresa:

url =  "https://www.receitaws.com.br/v1/cnpj/" + (i['cnpj']) ;
response = requests.request("GET", url)
conteudo = response
print(response.text)

arquivo = open('saidajson.txt','a')
arquivo.write(response.text)
arquivo.write('\n')

When I print the content on the screen is right, but when I open the letter txt like "ç,ã", it looks like "".

How can I fix this?

Obs: Receitaws is an API to get data from the IRS through CNPJ. The result of the query is in JSON.

  • 1

    Ever tried to use .encode('utf-8') ?

  • You have stopped presenting this problem. But I will remember your suggestion if it happens again. Obgd

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.