httpx
httpx copied to clipboard
Httpx is not encoding "%" symbol while sending requests
Discussed in https://github.com/encode/httpx/discussions/3094
Originally posted by heysarthak February 14, 2024 Hi team,
I am ussing httpx plugin, while sending httpx query "ngi%abc.com" . ideally "%" symbol should be encoded as "%25" but it is still sending as the same "%".
can we please have a fix for this.
% character has a special meaning in URLs, representing the start of a percent-encoded character. To include a literal % character in a URL, it must be percent-encoded as %25.
You can manually encode the query parameters in Python using the urllib.parse module:
from urllib.parse import quote
import httpx
query_param = "ngi%abc.com"
encoded_query_param = quote(query_param)
url = f"https://example.com/search?q={encoded_query_param}"
resp = httpx.get(url)