Closed
Description
This host lacks a Location: in this redir -- a not unusual thing on the Internets:
$ curl -D /dev/tty https://www.enterprisecarshare.com/robots.txt
HTTP/1.1 302 Moved Temporarily
Content-Type: text/html;charset=UTF-8
Dispatcher: dispatcher 1d
Server: Apache
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Length: 0
Cache-Control: max-age=168018
Expires: Tue, 15 Nov 2016 02:30:09 GMT
Date: Sun, 13 Nov 2016 03:49:51 GMT
Connection: keep-alive
I updated to 1.1.0, and if there's allow_redirects=True the code now calls yarl.URL(None) which throws
TypeError: Constructor parameter should be str
which is not so super-useful to the programmer! May I suggest instead looking to see if we're about to pass None into yarl.URL and in this case raise ValueError(url + ' is a redirect but lacks a Location: or URI: header')
$ python bug.py
Traceback (most recent call last):
File "bug.py", line 11, in <module>
loop.run_until_complete(main(url))
File "/home/lindahl/.pyenv/versions/3.5.2/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
return future.result()
File "/home/lindahl/.pyenv/versions/3.5.2/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/home/lindahl/.pyenv/versions/3.5.2/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "bug.py", line 6, in main
async with session.get(url, allow_redirects=True) as response:
File "/home/lindahl/.pyenv/versions/3.5.2/lib/python3.5/site-packages/aiohttp/client.py", line 558, in __aenter__
self._resp = yield from self._coro
File "/home/lindahl/.pyenv/versions/3.5.2/lib/python3.5/site-packages/aiohttp/client.py", line 245, in _request
resp.headers.get(hdrs.URI))
File "/home/lindahl/.pyenv/versions/3.5.2/lib/python3.5/site-packages/yarl/__init__.py", line 150, in __init__
raise TypeError("Constructor parameter should be str")
TypeError: Constructor parameter should be str
$ more bug.py
import asyncio
import aiohttp
async def main(url):
async with aiohttp.ClientSession() as session:
async with session.get(url, allow_redirects=True) as response:
await response.read()
url = 'https://www.enterprisecarshare.com/robots.txt'
loop = asyncio.get_event_loop()
loop.run_until_complete(main(url))