How do I add a query value with no key to a URL

A complete example URL would look like:
https://privatebin.net/?705d3509391e4d9a#ErLjeZzmD1DTsNoeLfPZGzKR3ACLPyfCJpbB1ZoTsoEX

(The example just points to a paste that says Hello World!)

>>> import httpx
>>> base = "https://privatebin.net/"
>>> id = "705d3509391e4d9a"
>>> r = httpx.get("https://privatebin.net", params={'': id}, headers={"X-Requested-With": "JSONHttpRequest"})
>>> r.json()
{'status': 1, 'message': 'Invalid paste ID.'}
>>> r.url
URL('https://privatebin.net?=705d3509391e4d9a')
>>> 

params={'': id} ends up with ?=705d3509391e4d9a which is evidently incorrect. How do I construct the URL properly?

You want to manually construct an httpx.Url object:

>>> import httpx
>>> base = "https://privatebin.net/"
>>> p_id = "705d3509391e4d9a"
>>> frag = "ErLjeZzmD1DTsNoeLfPZGzKR3ACLPyfCJpbB1ZoTsoEX"
>>> url = httpx.URL(base, query=p_id.encode(), fragment=frag)
>>> r = httpx.get(url, headers={"X-Requested-With": "JSONHttpRequest"})

Are you sure that that’s a fragment? I would have described it as a query string. “Fragment” usually means the part after the hash, which doesn’t apply to the HTTP request itself.

Exactly, now please look at the example URL given. I agree that this is a bit weird usage of the fragment, but I am pretty sure it is the fragment.

Doh. I did look at it before posting, but somehow didn’t actually see the hash sign in there. Don’t mind me, you were right to start with.

That works, thank you. After seeing your example, I realized I can also pass id as string to params directly to httpx.get to get the same result.