Monarch
(Monarch)
March 8, 2025, 8:49pm
1
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?
MegaIng
(Cornelius Krupp)
March 8, 2025, 9:42pm
2
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"})
Rosuav
(Chris Angelico)
March 9, 2025, 2:31am
3
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.
MegaIng
(Cornelius Krupp)
March 9, 2025, 2:32am
4
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.
Rosuav
(Chris Angelico)
March 9, 2025, 2:34am
5
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.
Monarch
(Monarch)
March 9, 2025, 5:37pm
6
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.