When writing code with httpx that calls services like the Github OAuth flow I end up getting errors like:
Request forbidden by administrative rules.
Please make sure your request has a User-Agent header.
You can see more auto-generated analysis and a coding example here: https://github.com/adewale/python-workers-issues/tree/main/3-httpx-headers
It seems like httpx on Python Workers strips out the User-Agent header. Switching to native js_fetch fixes it.
if HAS_PYODIDE:
opts = _to_js_value({"method": method, "headers": all_headers})
response = await js.fetch(url, opts)
...
else:
# CPython fallback — httpx works correctly here
import httpx
async with httpx.AsyncClient(timeout=httpx.Timeout(timeout)) as client:
resp = await client.request(method, url, headers=all_headers, content=body)
...
When writing code with httpx that calls services like the Github OAuth flow I end up getting errors like:
You can see more auto-generated analysis and a coding example here: https://github.com/adewale/python-workers-issues/tree/main/3-httpx-headers
It seems like httpx on Python Workers strips out the User-Agent header. Switching to native js_fetch fixes it.