cloudflare / cloudflare/workers-py

When using httpx the user agent header is missing which breaks use cases like Github OAuth flows

Open
#68 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
103
Forks
22
Avg merge
2d 1h
Merged PRs (30d)
30

Description

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.
```python
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)
...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.