httpx: URL cached incorrectly

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

To reproduce

async def asgi(scope, receive, send):
    print(scope)
    await send(
        {
            "type": "http.response.start",
            "status": 200,
            "headers": [],
        }
    )
    await send({"type": "http.response.body", "body": ""})


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(asgi, interface="asgi3", port=65432)
import httpx

base_url = "http://127.0.0.1:65432/"
client = httpx.Client(proxies=None)
client.post(base_url + "a").raise_for_status()
client.post(base_url + "b").raise_for_status()

Actual behavior

In the first request, everything was normal, but in the second request, there was an error in the URL! http://127.0.0.1:65432 was again incorrectly appended to the URL.

Debugging material

Server output:

{'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 65432), 'client': ('127.0.0.1', 7846), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': '/a', 'raw_path': b'/a', 'query_string': b'', 'headers': [(b'host', b'127.0.0.1:65432'), (b'content-length', b'0'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate'), (b'connection', b'keep-alive'), (b'user-agent', b'python-httpx/0.16.1')]}
INFO:     127.0.0.1:7846 - "POST /a HTTP/1.1" 200 OK
{'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 65432), 'client': ('127.0.0.1', 7846), 'scheme': 'http', 'method': 'POST', 'root_path': '', 'path': 'http://127.0.0.1:65432/b', 'raw_path': b'http://127.0.0.1:65432/b', 'query_string': b'', 'headers': [(b'host', b'127.0.0.1:65432'), (b'content-length', b'0'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate'), (b'connection', b'keep-alive'), (b'user-agent', b'python-httpx/0.16.1')]}
INFO:     127.0.0.1:7846 - "POST http%3A//127.0.0.1%3A65432/b HTTP/1.1" 200 OK

Environment

  • OS: Windows10
  • Python version: 3.7.4
  • HTTPX version: 0.16.1
  • HTTP proxy: no
  • Custom certificates: no

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

So… since this hasn’t yet been reproduced by anyone, one possibility is that either your httpx or your uvicorn source isn’t in a pristine state locally (eg. been edited for debugging or something) and that’s what’s causing the issue.

Some things that would be worth trying would be:

  • Isolating if the issue you’re seeing is client side or server side. Try running gunicorn instead of uvicorn, and sending the requests to that - are you still seeing the same error?
  • Make sure to set up a completely clean virtualenv, and ensure that you’re running within that.