0
Remaking the question in an attempt to make it clearer.
A webhook calls my API by sending a POST request. On the request body contains the url of a ZIP file.
Using the requests library, I perform a GET at the file url. I need to extract this few files from this zip and carry out a number of processes. The problem is that while trying to extract the file I come across the following error message:
'ascii' codec can't encode character '\\xa2' in position 45: ordinal not in range(128)
Request code and attempt to extract the file:
import io
import requests
from zipfile import ZipFile
response = requests.get(url)
with ZipFile(io.BytesIO(response.content)) as thezip:
thezip.extractall()
When I print out the list of file names:
with ZipFile(io.BytesIO(response.content)) as thezip:
print(thezip.namelist())
['Nao_Consistido/', 'Nao_Consistido/Relat\xc2\xa2rio de Previs\xc3\x86o de Vaz\xc3\x86o - Limite Inferior - LI.xls', 'Nao_Consistido/Relat\xc2\xa2rio de Previs\xc3\x86o de Vaz\xc3\x86o - Limite Superior - LS.xls', 'Nao_Consistido/Relat\xc2\xa2rio_de_Previs\xc3\x86o de Vaz\xc3\xa4es_PMO_de_DEZEMBRO_2019-preliminar.xls', 'Nao_Consistido/Todos_LI.prv', 'Nao_Consistido/Todos_LS.prv', 'Nao_Consistido/Todos_VE.prv']
I already set the PYTHONIOENCODING environment variable to utf-8 and it didn’t work. EDIT: After some tests I realized that the problem occurs only on the server (linux system), locally on Windows 10 does not occur.
Gustavo, it would be better if you [Dit] your previous question than create a new one, a question is only closed until its author improves it.. It is not a definite situation...
– fernandosavio
I made this edition but question remained closed, it occurs automatically?
– Gustavo Serafim
No, there is a vote for the reopening. The helping explains the operation better. What you can do is comment there and ask feedback for the community... so you will know what to improve on the question.
– fernandosavio
Okay thanks, I’ll do
– Gustavo Serafim