Hi I'm tring to run the code below and i get an error, HTTPError: Forbidden. It tells me that the line with a problem is in the requests.py file in the urllib folder. I wanted to extract data from an online website.
This is my code which i try to run
import pandas as pd
import geopandas as gpd
data = pd.read_html('https://www.worldometers.info/coronavirus/')
And this is the response i get from the spyder console
Python 3.8.2 (default, Mar 26 2020, 15:53:00)
Type "copyright", "credits" or "license" for more information.
IPython 7.13.0 -- An enhanced Interactive Python.
runfile('/home/evans/Desktop/GIS DEVELOPMENTS/PROJECTS/Coronavirus2020.py', wdir='/home/evans/Desktop/GIS DEVELOPMENTS/PROJECTS') Traceback (most recent call last):
File "/home/evans/Desktop/GIS DEVELOPMENTS/PROJECTS/Coronavirus2020.py", line 5, in data = pd.read_html('https://www.worldometers.info/coronavirus/')
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/io/html.py", line 1085, in read_html return _parse(
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/io/html.py", line 895, in _parse tables = p.parse_tables()
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/io/html.py", line 213, in parse_tables tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/io/html.py", line 733, in _build_doc raise e
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/io/html.py", line 714, in _build_doc with urlopen(self.io) as f:
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/io/common.py", line 141, in urlopen return urllib.request.urlopen(*args, **kwargs)
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout)
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/urllib/request.py", line 531, in open response = meth(req, response)
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error(
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/urllib/request.py", line 569, in error return self._call_chain(*args)
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args)
File "/home/evans/anaconda3/envs/myenv/lib/python3.8/urllib/request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp)
HTTPError: Forbidden
The problem at first was that lxml was missing, so i decided to install it from my environment using pip3 install lxml
, but this is the return message i got.
Requirement already satisfied: lxml in /usr/lib/python3/dist-packages (4.4.1).
But this is not in my environment folder, it is in the base/root folder. So i just decided to use pip install lxml and it worked. Then when i executed it, it returned the above error.
I will appreciate any guidance to help me overcome this problem.