1

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"

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    try install certifi: `python -m pip install certifi` – eyllanesc Apr 02 '20 at 22:38
  • Does this answer your question? [How do I download a file over HTTP using Python?](https://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python) – foglerit Apr 02 '20 at 22:39
  • 1
    Why don't you check https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error? There is also a chance, depending on how confidential the request is, to deactivate HTTPS. Check https://stackoverflow.com/questions/33770129/how-do-i-disable-the-ssl-check-in-python-3-x – Tomás Denis Reyes Sánchez Apr 02 '20 at 22:42
  • If you can, use [requests](https://2.python-requests.org/en/master/) for HTTP(S). It takes care of a lot of the messy details for you. – Roland Smith Apr 02 '20 at 23:00
  • Does this answer your question? [urllib and "SSL: CERTIFICATE\_VERIFY\_FAILED" Error](https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error) – mx0 Sep 01 '20 at 11:46

1 Answers1

0

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.