I am currently trying to collect data from the Bank of England's website using their API, however, I keep getting an Error 500 when I pass the URL through pandas.read_csv() or requests.get(). I have included below an example:
pandas.read_csv("https://www.bankofengland.co.uk/boeapps/database/_iadb-fromshowcolumns.asp?csv.x=yes&Datefrom=01/Jan/1963&Dateto=13/Jan/2022&SeriesCodes=LPMAUYN&CSVF=TN&UsingCodes=Y&VPD=Y&VFD=N")
The strange thing is that if one manually enters the above URL in his/her browser then the CSV file is downloaded and no error is raised. Furthermore, this used to work in the past but it no longer seems to be the case.
Am I doing anything wrong from my end, or is this just a problem from the server's end?
Thanks in advance.
the browser always sends data in the headers which you could also do with requests.
request below returns code 200.
import requests
url = "https://www.bankofengland.co.uk/boeapps/database/_iadb-fromshowcolumns.asp?" \
"csv.x=yes&Datefrom=01/Jan/1963&Dateto=13/Jan/2022&SeriesCodes=LPMAUYN&CSVF=TN&UsingCodes=Y&VPD=Y&VFD=N"
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/54.0.2840.90 '
'Safari/537.36'
}
response = requests.get(url, headers=headers)
print(response.text)
output:
DATE,LPMAUYN
30 Jun 1982,145329
31 Jul 1982,146842
31 Aug 1982,148277
30 Sep 1982,149702
31 Oct 1982,150555
30 Nov 1982,151983
31 Dec 1982,153887
...
31 May 2021,2894480
30 Jun 2021,2912525
31 Jul 2021,2917566
31 Aug 2021,2933716
30 Sep 2021,2954865
31 Oct 2021,2972962
30 Nov 2021,2992824