Fastapi: [BUG] Error with http3 AsyncClient

Created on 21 Jun 2019  路  3Comments  路  Source: tiangolo/fastapi

Describe the bug
Error using fastapi with http3 library https://github.com/encode/http3

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:

  • OS: [e.g. macOS]
  • python 3.7.2
  • FastAPI Version 0.30.0
  • http3 version 0.6.0
bug

Most helpful comment

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

All 3 comments

Sorry, I'm not sure what you are trying to achieve.

But await can only be used inside of async functions, so I guess that might be the first thing to check.

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.

Just a quick question @tiangolo, any plans to document how to add http3 support into FastAPI ? using aioquic maybe ?
I'm loving it, migrating from django/node frameworks to FastAPI.
Hoping, in a soon future, to contribute to the project.

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

Was this page helpful?
0 / 5 - 0 ratings