You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While reusing some code I didn't notice that it required an environment variable to be defined.
This led to the URL used for the requests being None. However, calling ClientSession.request with str_or_url equal to None doesn't trigger an InvalidURL exception, but a TypeError on URL(str_or_url).
I think TypeError is pretty common exception for invalid argument type. InvalidURL is a kind of ValueError which is raised when the type is correct but the value is not.
>>> int("10")
10
>>> int("not-valid")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'not-valid'
>>> int(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Right, it's just that having a wrong type also has the consequence of producing and invalid URL, so maybe raising an InvalidURL exception would be a better hint of what is wrong. Or maybe not, as the TypeError is more precise.
Long story short
While reusing some code I didn't notice that it required an environment variable to be defined.
This led to the URL used for the requests being None. However, calling
ClientSession.request
withstr_or_url
equal toNone
doesn't trigger anInvalidURL
exception, but a TypeError onURL(str_or_url)
.https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L361
Expected behaviour
Consider None as an invalid URL and raise an according exception (InvalidURL)
Actual behaviour
TypeError is rased in
yarl.URL.__new__
Steps to reproduce
Call
ClientSession.request(method='GET', str_or_url=None, ...)
Your environment
Python 3.7 and aiohttp 3.5.2 in a virtualenv.
Running Ubuntu 18.04.
client.
The text was updated successfully, but these errors were encountered: