[Tutor] Error while opening the url from pandas library
Harsh Sheth
harsheth97 at gmail.com
Mon Sep 7 08:45:35 EDT 2020
Dear Sir,
I am trying to open the csv file from the net. However I'm facing this
error. I am mentioning the code and the error message for your reference.
Code:
import pandas as pd
url = "
https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length','sepal-width','petal-length','petal-width','class']
dataset = pd.read_csv(url, names=names)
Error Message:
TimeoutError Traceback (most recent call last)
/usr/lib/python3.8/urllib/request.py in do_open(self, http_class, req,
**http_conn_args) 1325 try: -> 1326 h.request(req.get_method(),
req.selector, req.data, headers, 1327
encode_chunked=req.has_header('Transfer-encoding'))
/usr/lib/python3.8/http/client.py in request(self, method, url, body,
headers, encode_chunked) 1239 """Send a complete request to the server.""" ->
1240 self._send_request(method, url, body, headers, encode_chunked) 1241
/usr/lib/python3.8/http/client.py in _send_request(self, method, url, body,
headers, encode_chunked) 1285 body = _encode(body, 'body') -> 1286 self.
endheaders(body, encode_chunked=encode_chunked) 1287
/usr/lib/python3.8/http/client.py in endheaders(self, message_body,
encode_chunked) 1234 raise CannotSendHeader() -> 1235 self._send_output(
message_body, encode_chunked=encode_chunked) 1236
/usr/lib/python3.8/http/client.py in _send_output(self, message_body,
encode_chunked) 1005 del self._buffer[:] -> 1006 self.send(msg) 1007
/usr/lib/python3.8/http/client.py in send(self, data) 945 if
self.auto_open: -->
946 self.connect() 947 else: /usr/lib/python3.8/http/client.py in connect
(self) 1401 -> 1402 super().connect() 1403 /usr/lib/python3.8/http/client.py
in connect(self) 916 """Connect to the host and port specified in
__init__.""" --> 917 self.sock = self._create_connection( 918
(self.host,self.port), self.timeout, self.source_address)
/usr/lib/python3.8/socket.py in create_connection(address, timeout,
source_address) 807 try: --> 808 raise err 809 finally:
/usr/lib/python3.8/socket.py in create_connection(address, timeout,
source_address) 795 sock.bind(source_address) --> 796 sock.connect(sa) 797 #
Break explicitly a reference cycle TimeoutError: [Errno 110] Connection
timed out During handling of the above exception, another exception
occurred: URLError Traceback (most recent call last)
<ipython-input-23-3970a2532cfd> in <module> 1 url = "
https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" 2
names = ['sepal-length','sepal-width','petal-length','petal-width','class']
---->
3 dataset = pd.read_csv(url, names=names)
/usr/local/lib/python3.8/dist-packages/pandas/io/parsers.py in
read_csv(filepath_or_buffer,
sep, delimiter, header, names, index_col, usecols, squeeze, prefix,
mangle_dupe_cols, dtype, engine, converters, true_values, false_values,
skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na,
na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format,
keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize,
compression, thousands, decimal, lineterminator, quotechar, quoting,
doublequote, escapechar, comment, encoding, dialect, error_bad_lines,
warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
684 ) 685 --> 686 return _read(filepath_or_buffer, kwds) 687 688
/usr/local/lib/python3.8/dist-packages/pandas/io/parsers.py in
_read(filepath_or_buffer,
kwds) 432 # though mypy handling of conditional imports is difficult. 433 #
See https://github.com/python/mypy/issues/1297 --> 434 fp_or_buf, _,
compression, should_close = get_filepath_or_buffer( 435 filepath_or_buffer,
encoding, compression 436 )
/usr/local/lib/python3.8/dist-packages/pandas/io/common.py in
get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode,
storage_options) 181 if isinstance(filepath_or_buffer, str) and is_url(
filepath_or_buffer): 182 # TODO: fsspec can also handle HTTP via requests,
but leaving this unchanged --> 183 req = urlopen(filepath_or_buffer) 184
content_encoding = req.headers.get("Content-Encoding", None) 185 if
content_encoding == "gzip":
/usr/local/lib/python3.8/dist-packages/pandas/io/common.py in urlopen(*args,
**kwargs) 135 import urllib.request 136 --> 137 return urllib.request.
urlopen(*args, **kwargs) 138 139 /usr/lib/python3.8/urllib/request.py in
urlopen(url, data, timeout, cafile, capath, cadefault, context) 220 else:
221 opener = _opener --> 222 return opener.open(url, data, timeout) 223 224
def install_opener(opener): /usr/lib/python3.8/urllib/request.py in open(self,
fullurl, data, timeout) 523 524 sys.audit('urllib.Request', req.full_url,
req.data, req.headers, req.get_method()) --> 525 response = self._open(req,
data) 526 527 # post-process response /usr/lib/python3.8/urllib/request.py
in _open(self, req, data) 540 541 protocol = req.type --> 542 result =
self._call_chain(self.handle_open, protocol, protocol + 543 '_open', req)
544 if result: /usr/lib/python3.8/urllib/request.py in _call_chain(self,
chain, kind, meth_name, *args) 500 for handler in handlers: 501 func =
getattr(handler, meth_name) --> 502 result = func(*args) 503 if result is
not None: 504 return result /usr/lib/python3.8/urllib/request.py in
https_open(self, req) 1367 1368 def https_open(self, req): -> 1369 return
self.do_open(http.client.HTTPSConnection, req, 1370 context=self._context,
check_hostname=self._check_hostname) 1371
/usr/lib/python3.8/urllib/request.py in do_open(self, http_class, req,
**http_conn_args) 1327 encode_chunked=req.has_header('Transfer-encoding'))
1328 except OSError as err: # timeout error -> 1329 raise URLError(err) 1330
r = h.getresponse() 1331 except: URLError: <urlopen error [Errno 110]
Connection timed out>
Note : I'm using the online jupyter IDLE. Although I tried downloading the
file and providing the path it still showed the error.
Regards,
Harsh
More information about the Tutor
mailing list