Reputation: 570
I have to make network requests to an API endpoint. However requests only encodes query parameters and not the url path.
Consider below for exmaple
https://example.com/Nova#123
The server endpoint however accepts https://example.com/Nova%23123
. How can I do this with requests? String replacement is not a solution considering other special characters.
Upvotes: 0
Views: 388
Reputation: 18136
There is urllib.parse.quote:
from urllib.parse import urljoin, quote
print(urljoin('https://example.com', quote('Nova#123')))
Out:
https://example.com/Nova%23123
Upvotes: 1