Error with http3 AsyncClient #8148
-
Describe the bug To Reproduce from fastapi import FastAPI
app = FastAPI()
@app.get('/')
async def root():
return
import http3
client = http3.AsyncClient(app=app)
await client.get('http://test/') Traceback: Traceback (most recent call last):
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3292, in run_code
last_expr = (yield from self._async_exec(code_obj, self.user_ns))
File "<ipython-input-7-3f0100d218b8>", line 4, in async-def-wrapper
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/client.py", line 302, in get
timeout=timeout,
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/client.py", line 534, in request
timeout=timeout,
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/client.py", line 136, in send
await response.read()
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/models.py", line 855, in read
self._content = b"".join([part async for part in self.stream()])
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/models.py", line 855, in <listcomp>
self._content = b"".join([part async for part in self.stream()])
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/models.py", line 866, in stream
async for chunk in self.raw():
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/models.py", line 885, in raw
await self.close()
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/models.py", line 895, in close
await self.on_close()
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/dispatch/asgi.py", line 131, in on_close
raise app_exc
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/http3/dispatch/asgi.py", line 101, in run_app
await app(scope, receive, send)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/applications.py", line 133, in __call__
await self.error_middleware(scope, receive, send)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/middleware/errors.py", line 122, in __call__
raise exc from None
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/middleware/errors.py", line 100, in __call__
await self.app(scope, receive, _send)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/exceptions.py", line 73, in __call__
raise exc from None
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/exceptions.py", line 62, in __call__
await self.app(scope, receive, sender)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/routing.py", line 585, in __call__
await route(scope, receive, send)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/routing.py", line 207, in __call__
await self.app(scope, receive, send)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/routing.py", line 40, in app
response = await func(request)
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/fastapi/routing.py", line 109, in app
dependency_overrides_provider=dependency_overrides_provider,
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/fastapi/dependencies/utils.py", line 376, in solve_dependencies
dependant.query_params, request.query_params
File "/Users/dzmitrysianiuk/.local/share/virtualenvs/backend-CYvvO53x/lib/python3.7/site-packages/starlette/requests.py", line 63, in query_params
self._query_params = QueryParams(self._scope["query_string"])
KeyError: 'query_string' Environment:
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Sorry, I'm not sure what you are trying to achieve. But I'll close this, but feel free to add more comments. Also, if you still have problems, you can create a self-contained example that I can run and see your error. |
Beta Was this translation helpful? Give feedback.
-
Just a quick question @tiangolo, any plans to document how to add http3 support into FastAPI ? using aioquic maybe ? |
Beta Was this translation helpful? Give feedback.
-
For what it's worth, the "http3" library referenced in the original post in this issue has been renamed to httpx. @Jonatha-Varjao If you are referring to the HTTP/3 protocol (and given your reference to QUIC, I think you probably are), my understanding is that support for that would happen at a lower level in the stack -- probably inside the ASGI server. So, it's a matter of gunicorn/uvicorn/your ASGI server of choice adding support for HTTP/3. I think uvicorn still hasn't added HTTP/2 support yet (though it is planned); I'm not aware of any ASGI servers offering HTTP/3 support yet (though I haven't loooked). |
Beta Was this translation helpful? Give feedback.
-
Hi Tiangolo, Just wanted to make you aware that a HTTP3 lib project now exists for Python: https://github.com/aiortc/aioquic I'm not a lib dev but it sounds like they have designed it to be implementable by other lib authors into their own project. Maybe it can be integrated to FastAPI. Hope that helps in some way. Also very sorry if I posted this in a wrong section or something. Just passing on tech news I think you might find interesting without creating a new HTTP3 thread. With Love, |
Beta Was this translation helpful? Give feedback.
-
Just as for probable reason for such traceback for me was a wrong endpoint passed to get method, for example check for slashes more carefullly |
Beta Was this translation helpful? Give feedback.
-
Thanks for making this post, and sorry if I'm creating unnecessary noise. You can use QUIC with newer versions of FastAPI if you import asyncio
from hypercorn.config import Config
from hypercorn.asyncio import serve
config = Config()
config.bind = ["localhost:5000"]
config.quic_bind = ["localhost:5000"]
config.keyfile = "/path/to/keyfile.pem"
config.certfile = "/path/to/certfile.pem"
asyncio.run(serve(fastapi_app, config)) |
Beta Was this translation helpful? Give feedback.
For what it's worth, the "http3" library referenced in the original post in this issue has been renamed to httpx.
@Jonatha-Varjao If you are referring to the HTTP/3 protocol (and given your reference to QUIC, I think you probably are), my understanding is that support for that would happen at a lower level in the stack -- probably inside the ASGI server. So, it's a matter of gunicorn/uvicorn/your ASGI server of choice adding support for HTTP/3.
I think uvicorn still hasn't added HTTP/2 support yet (though it is planned); I'm not aware of any ASGI servers offering HTTP/3 support yet (though I haven't loooked).