-
Notifications
You must be signed in to change notification settings - Fork 14
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
urllib.parse.Misimplementation of urljoin #360
Comments
Hi, can you try this code snippet? Make sure you put a trailing slash from urllib.parse import urljoin
base_url = "example.org/orion/"
url = urljoin(base_url, "version")
assert url == "example.org/orion/version" If it is still an issue, please specify your python environment more specifically. |
@djs0109 The problem persists because the ngsi_version contains a '/' leading wrong concatenation. of the url. |
@tstorek good point. I will fix the version enumeration, i.e. remove the starting class NgsiURLVersion(str, Enum):
"""
URL part that defines the NGSI version for the API.
"""
v2_url = "v2"
ld_url = "ngsi-ld/v1" To reproduce from urllib.parse import urljoin
base_url = "example.org/orion/"
version = "v2"
url_correct = urljoin(base_url, f"{version}/entities")
assert url_correct == 'example.org/orion/v2/entities'
version = "/v2"
url_wrong = urljoin(base_url, f"{version}/entities")
assert url_wrong == '/v2/entities' |
@djs0109 thanks, at the same time it would be good to validate the baserul. Maybe using pydantics AnyHttpUrl. As I understand that one will always add the trailing slash if missing |
Describe the bug
The urllib.parse.urljoin, e.g. when using orion base url and the version endpoint in the get_version() function, works a little different than originally expected.
urljoin(url1, url2)
E.g. if orion is running behind "example.org/orion" and I run the get_version, the function will end up querying "example.org/version".
This is because urljoin does not simply concatenate the URLs but cuts the first url depending on how many "/" are part of second url.
To Reproduce
see above, give the orion client a url with a path /orion
Expected behavior
Get version; instead getting nothing cause url is wrong.
The text was updated successfully, but these errors were encountered: