Skip to content

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

@adewale

Description

@adewale

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions