fastbook icon indicating copy to clipboard operation
fastbook copied to clipboard

error in search_images_ddg()

Open Himanshunitrr opened this issue 4 years ago • 3 comments
trafficstars

The code on GitHub is correct but it's incorrect in python package. I have written in detail about the issue at https://forums.fast.ai/t/getting-error-while-downloading-images-using-api/89187

I would have changed it but I don't know how to do it. (It's a mere deletion of .decode())

Himanshunitrr avatar Jun 19 '21 12:06 Himanshunitrr

It seems like this has been fixed in the latest release (0.0.18) -- Does it work for you if you update to that version?

zxul767 avatar Sep 29 '21 17:09 zxul767

I'm getting this when running search_images_ddg() in Paperspace. Unsure how to fix and proceed.


TimeoutError Traceback (most recent call last) File ~/mambaforge/lib/python3.9/urllib/request.py:1346, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1345 try: -> 1346 h.request(req.get_method(), req.selector, req.data, headers, 1347 encode_chunked=req.has_header('Transfer-encoding')) 1348 except OSError as err: # timeout error

File ~/mambaforge/lib/python3.9/http/client.py:1285, in HTTPConnection.request(self, method, url, body, headers, encode_chunked) 1284 """Send a complete request to the server.""" -> 1285 self._send_request(method, url, body, headers, encode_chunked)

File ~/mambaforge/lib/python3.9/http/client.py:1331, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked) 1330 body = _encode(body, 'body') -> 1331 self.endheaders(body, encode_chunked=encode_chunked)

File ~/mambaforge/lib/python3.9/http/client.py:1280, in HTTPConnection.endheaders(self, message_body, encode_chunked) 1279 raise CannotSendHeader() -> 1280 self._send_output(message_body, encode_chunked=encode_chunked)

File ~/mambaforge/lib/python3.9/http/client.py:1040, in HTTPConnection._send_output(self, message_body, encode_chunked) 1039 del self._buffer[:] -> 1040 self.send(msg) 1042 if message_body is not None: 1043 1044 # create a consistent interface to message_body

File ~/mambaforge/lib/python3.9/http/client.py:980, in HTTPConnection.send(self, data) 979 if self.auto_open: --> 980 self.connect() 981 else:

File ~/mambaforge/lib/python3.9/http/client.py:1447, in HTTPSConnection.connect(self) 1445 "Connect to a host on a given (SSL) port." -> 1447 super().connect() 1449 if self._tunnel_host:

File ~/mambaforge/lib/python3.9/http/client.py:946, in HTTPConnection.connect(self) 945 """Connect to the host and port specified in init.""" --> 946 self.sock = self._create_connection( 947 (self.host,self.port), self.timeout, self.source_address) 948 # Might fail in OSs that don't implement TCP_NODELAY

File ~/mambaforge/lib/python3.9/socket.py:844, in create_connection(address, timeout, source_address) 843 try: --> 844 raise err 845 finally: 846 # Break explicitly a reference cycle

File ~/mambaforge/lib/python3.9/socket.py:832, in create_connection(address, timeout, source_address) 831 sock.bind(source_address) --> 832 sock.connect(sa) 833 # 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) Input In [5], in <cell line: 1>() ----> 1 results = search_images_ddg('grizzly bear') 2 ims = results.attrgot('contentUrl') 3 len(ims)

File ~/mambaforge/lib/python3.9/site-packages/fastbook/init.py:57, in search_images_ddg(term, max_images) 55 assert max_images<1000 56 url = 'https://duckduckgo.com/' ---> 57 res = urlread(url,data={'q':term}) 58 searchObj = re.search(r'vqd=([\d-]+)&', res) 59 assert searchObj

File ~/mambaforge/lib/python3.9/site-packages/fastcore/net.py:111, in urlread(url, data, headers, decode, return_json, return_headers, timeout, **kwargs) 109 "Retrieve url, using data dict or kwargs to POST if present" 110 try: --> 111 with urlopen(url, data=data, headers=headers, timeout=timeout, **kwargs) as u: res,hdrs = u.read(),u.headers 112 except HTTPError as e: 113 if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None

File ~/mambaforge/lib/python3.9/site-packages/fastcore/net.py:105, in urlopen(url, data, headers, timeout, **kwargs) 103 if not isinstance(data, (str,bytes)): data = urlencode(data) 104 if not isinstance(data, bytes): data = data.encode('ascii') --> 105 return _opener.open(urlwrap(url, data=data, headers=headers), timeout=timeout)

File ~/mambaforge/lib/python3.9/urllib/request.py:517, in OpenerDirector.open(self, fullurl, data, timeout) 514 req = meth(req) 516 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method()) --> 517 response = self._open(req, data) 519 # post-process response 520 meth_name = protocol+"_response"

File ~/mambaforge/lib/python3.9/urllib/request.py:534, in OpenerDirector._open(self, req, data) 531 return result 533 protocol = req.type --> 534 result = self._call_chain(self.handle_open, protocol, protocol + 535 '_open', req) 536 if result: 537 return result

File ~/mambaforge/lib/python3.9/urllib/request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 492 for handler in handlers: 493 func = getattr(handler, meth_name) --> 494 result = func(*args) 495 if result is not None: 496 return result

File ~/mambaforge/lib/python3.9/urllib/request.py:1389, in HTTPSHandler.https_open(self, req) 1388 def https_open(self, req): -> 1389 return self.do_open(http.client.HTTPSConnection, req, 1390 context=self._context, check_hostname=self._check_hostname)

File ~/mambaforge/lib/python3.9/urllib/request.py:1349, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1346 h.request(req.get_method(), req.selector, req.data, headers, 1347 encode_chunked=req.has_header('Transfer-encoding')) 1348 except OSError as err: # timeout error -> 1349 raise URLError(err) 1350 r = h.getresponse() 1351 except:

URLError: <urlopen error [Errno 110] Connection timed out>

mihaim avatar Sep 14 '22 17:09 mihaim

Seeing this timeout error with the newer DDGS version (3.9.4) too.

drscotthawley avatar Nov 09 '23 20:11 drscotthawley