Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarl.URL.build() fails when host=None #808

Closed
1 task done
paulpapacz opened this issue Jan 9, 2023 · 1 comment · Fixed by #809
Closed
1 task done

yarl.URL.build() fails when host=None #808

paulpapacz opened this issue Jan 9, 2023 · 1 comment · Fixed by #809
Labels

Comments

@paulpapacz
Copy link
Contributor

Describe the bug

When building a URL using yarl.URL.build() the command will fail with exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 248, in build
    cls._validate_authority_uri_abs_path(host=host, path=path)
  File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 706, in _validate_authority_uri_abs_path
    if len(host) > 0 and len(path) > 0 and not path.startswith("/"):
TypeError: object of type 'NoneType' has no len()

To Reproduce

yarl version 1.8.2

from yarl import URL

URL.build(scheme="http", host=None)

Expected behavior

Either passing without problems or some meaningful error/exception indicating that host cannot be None.

Logs/tracebacks

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 248, in build
    cls._validate_authority_uri_abs_path(host=host, path=path)
  File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 706, in _validate_authority_uri_abs_path
    if len(host) > 0 and len(path) > 0 and not path.startswith("/"):
TypeError: object of type 'NoneType' has no len()

Python Version

$ python --version
Python 3.10.6

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: /path/to/virtualenv/lib/python3.10/site-packages
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.8.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: /path/to/virtualenv/lib/python3.10/site-packages
Requires: idna, multidict
Required-by: aiohttp, template-api

OS

Ubuntu 22.04

Additional context

This should be easy to fix by simply adding the same check for host as those for scheme, authority, etc, in the condition here.

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@webknjaz
Copy link
Member

Looks like the related PR #809 got merged long ago and was included in v1.9.0.

@webknjaz webknjaz linked a pull request Nov 20, 2023 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants