kennethreitz/requests — Issue #381: requests.async -- catch DNS errors more explicitly?
Author: tokarina
Created: 2012-01-23 14:19:55+00:00
State: open

This is related to #380, however the manifestation is different when using requests.async

This could be handled by detected that the redirect URL is bogus. On the other hand, it would be good to have a more explicit exception than an low-level IOError when gevent's DNS infrastructure gets confused.

What's the best way to fix this?

```
>>> r = requests.get(
... 'http://travel.rr.com/in?a=roadrunner&;p=heroluxuryvacation&;url=/dealssearchcat=Luxury&;rp=t&;nv=t&;pz=15&;pgsrc=roadrunner',
... allow_redirects=False)
>>>
>>> r

>>> r.headers.location
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'CaseInsensitiveDict' object has no attribute 'location'
>>> r.headers.get('location')
'http://www.kayak.com?;nv=t&;pz=15&;url=%2Fdealssearchcat%3DLuxury&;pgsrc=roadrunner&;p=heroluxuryvacation&;rp=t'
>>>
>>>
>>> import requests.async
>>> r = requests.async.get('http://travel.rr.com/in?a=roadrunner&;p=heroluxuryvacation&;url=/dealssearchcat=Luxury&;rp=t&;nv=t&;pz=15&;pgsrc=roadrunner')
>>> r.send()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 514, in send
self._build_response(r)
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 253, in _build_response
request.send()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 492, in send
timeout=self.timeout,
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 336, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 217, in _make_request
conn.request(method, url, **httplib_request_kw)
File "httplib.py", line 970, in request
self._send_request(method, url, body, headers)
File "httplib.py", line 1004, in _send_request
self.endheaders(body)
File "httplib.py", line 966, in endheaders
self._send_output(message_body)
File "httplib.py", line 826, in _send_output
self.send(msg)
File "httplib.py", line 779, in send
self.connect()
File "httplib.py", line 760, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/pymodules/python2.7/gevent/socket.py", line 681, in getaddrinfo
_ttl, addrs = resolve_ipv4(host, evdns_flags)
File "/usr/lib/pymodules/python2.7/gevent/dns.py", line 56, in resolve_ipv4
core.dns_resolve_ipv4(name, flags, waiter.switch_args)
File "evdns.pxi", line 93, in gevent.core.dns_resolve_ipv4 (gevent/core.c:6533)
IOError: evdns_resolve_ipv4('www.kayak.com?;nv=t&;pz=15&;url=%2Fdealssearchcat%3DLuxury&;pgsrc=roadrunner&;p=heroluxuryvacation&;rp=t', 0) returned -1
>>>
```