Home > Enterprise >  Spyder pandas.read_html issue
Spyder pandas.read_html issue

Time:06-13

In a Python script I'm trying to run this code:

tables = pd.read_html("https://sdw.ecb.europa.eu/quickview.do?SERIES_KEY=120.EXR.D.CHF.EUR.SP00.A")

and I'm getting this error:

  File ~\anaconda3\lib\urllib\request.py:641 in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: Service Temporarily Unavailable

The funny thing is that this web page is working and if I execute the same code the standard Python environment (downloaded from python.org) I get no error and the code works as expected.

How can I fix this? I would like to use Anaconda as my development environment.

CodePudding user response:

The following code works for me in PyCharm:

import pandas as pd
import requests

headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36'}
url = 'https://sdw.ecb.europa.eu/quickview.do?SERIES_KEY=120.EXR.D.CHF.EUR.SP00.A'
r = requests.get(url, headers=headers)
df = pd.read_html(r.content, thousands=None, decimal=',')

Don't ask too often. They can get banned. Currency quotes can be taken elsewhere. And the fundamental data is updated not so often, not more than once a month.

  • Related