简体   繁体   中英

Download .xls file

I've been trying to download a.xls file using urllib like this

from urllib.request import urlretrieve as retrieve 
dls = "https://www.bvc.com.co/mercados/DescargaXlsServlet?archivo=acciones&fecha=2020-04-02&resultados=100&tipoMercado="
retrieve(dls,"Acciones.xls")

But I recieve a long error message starting with:

Traceback (most recent call last):
  File "C:\Users\quiki\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))

and ending with:

urllib.error.URLError: urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

I do not know if it has to do with the fact that the URL does not end with ".xls"

That's a ssl cert verification error. That means that the site's certificate is having some kind of problem.

Try this code, it disables the verification.

import requests

dls = "https://www.bvc.com.co/mercados/DescargaXlsServlet?archivo=acciones&  fecha=2020-04-02&resultados=100&tipoMercado="

with open("Acciones.xls","wb") as f:
    f.write(requests.get(dls,verify=False).content)

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM