I
I
Igor2018-10-17 09:04:51
Python
Igor, 2018-10-17 09:04:51

Wrong encoding when downloading excel file via python 3. How to fix?

Script code:

import requests
file = requests.get("https://login:[email protected]/export/[email protected]/myshop/prices.xls")
f = open("priceRF.xls", "wb")
f.write(file.text.encode('cp65001'))
f.close()
print("Done!")

The file is coming.
But inside the krakozyabra: pїЅpїЅpїЅ pїЅ
csv saves, Russian characters are read, with:
f = open("priceRF.csv", "w")
f.write(file.text)

But it's important to get .xls
Please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2018-10-17
@aif88

instead of:
> f.write(file.text.encode('cp65001'))
you need something like:
> f.write(file.content)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question