httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Httpx is not encoding "%" symbol while sending requests

Open heysarthak opened this issue 1 year ago • 1 comments

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.

heysarthak avatar Mar 11 '24 10:03 heysarthak

% 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)

deedy5 avatar Apr 06 '24 15:04 deedy5