emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.67k stars 79 forks source link

Granian does not work with Django ASGI #173

Closed jefer94 closed 8 months ago

jefer94 commented 8 months ago
granian --interface asgi mysite.asgi:application --no-opt
[INFO] Starting granian
[INFO] Listening at: 127.0.0.1:8000
[INFO] Spawning worker-1 with pid: 27092
[WARNING] Exception in lifespan protocol
Traceback (most recent call last):
  File "/home/v/dev/django-workers/.venv/lib/python3.11/site-packages/granian/asgi.py", line 24, in handle
    await self.callable(
  File "/home/v/dev/django-workers/.venv/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 165, in __call__
    raise ValueError(
ValueError: Django can only handle ASGI/HTTP connections, not lifespan.
[INFO] Started worker-1
[INFO] Started worker-1 runtime-1
[WARNING] Application callable raised an exception
Task exception was never retrieved
future: <Task finished name='Task-4' coro=<future_watcher_wrapper.<locals>.future_watcher() done, defined at /home/v/dev/django-workers/.venv/lib/python3.11/site-packages/granian/_futures.py:2> exception=AssertionError('Invalid ASGI message after request body: http.request')>
Traceback (most recent call last):
  File "/home/v/dev/django-workers/.venv/lib/python3.11/site-packages/granian/_futures.py", line 4, in future_watcher
    await inner(watcher.scope, watcher.proto)
  File "/home/v/dev/django-workers/.venv/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 170, in __call__
    await self.handle(scope, receive, send)
  File "/home/v/dev/django-workers/.venv/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 209, in handle
    task.result()
  File "/home/v/dev/django-workers/.venv/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 232, in listen_for_disconnect
    assert False, "Invalid ASGI message after request body: %s" % message["type"]
AssertionError: Invalid ASGI message after request body: http.request
"""
ASGI config for mysite project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

application = get_asgi_application()
app = application
## The following requirements were added by pip freeze:
activecampaign-python==1.0.10
adrf==0.1.3
aiodns==3.1.1
aiohttp==3.9.1
aiohttp-retry==2.8.3
aiosignal==1.3.1
amqp==5.2.0
aniso8601==9.0.1
annotated-types==0.6.0
anyio==4.2.0
asgiref==3.7.2
async-property==0.2.2
async-timeout==4.0.3
attrs==23.2.0
autobahn==23.6.2
Automat==22.10.0
Babel==2.14.0
beautifulsoup4==4.12.2
billiard==4.2.0
bleach==6.1.0
Brotli==1.1.0
cachetools==5.3.2
celery==5.3.6
certifi==2023.11.17
cffi==1.16.0
channels==4.0.0
channels-redis==4.1.0
charset-normalizer==3.3.2
circuitbreaker==2.0.0
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
constantly==23.10.4
contextlib2==21.6.0
coralogix-logger==2.0.6
cryptography==41.0.7
cssselect==1.2.0
cssutils==2.9.0
currencies==2020.12.12
daphne==4.0.0
defusedxml==0.7.1
Deprecated==1.2.14
distro==1.9.0
dj-database-url==2.1.0
Django==5.0.1
django-cors-headers==4.3.1
django-heroku==0.3.1
django-phonenumber-field==7.3.0
django-redis==5.4.0
django-sql-explorer==3.2.1
django-storages==1.14.2
djangorestframework==3.14.0
djangorestframework-csv==3.0.2
drf-yasg==1.21.7
eventbrite==3.3.5
exceptiongroup==1.2.0
expiringdict==1.2.2
Faker==12.0.1
fastjsonschema==2.19.1
frozenlist==1.4.1
gevent==23.9.1
google-api-core==2.15.0
google-auth==2.26.2
google-cloud-bigquery==3.15.0
google-cloud-bigquery-storage==2.24.0
google-cloud-core==2.4.1
google-cloud-datastore==2.19.0
google-cloud-firestore==2.14.0
google-cloud-ndb==2.2.2
google-cloud-recaptcha-enterprise==1.16.0
google-cloud-storage==2.14.0
google-crc32c==1.5.0
google-resumable-media==2.7.0
googleapis-common-protos==1.62.0
granian==0.7.5
graphene==3.3
graphene-django==3.2.0
graphene-django-optimizer==0.10.0
graphql-core==3.2.3
graphql-relay==3.2.0
greenlet==3.0.3
grpcio==1.60.0
grpcio-status==1.60.0
gunicorn==21.2.0
h11==0.14.0
h2==4.1.0
hiredis==2.3.2
hpack==4.0.0
httpcore==1.0.2
httpx==0.26.0
Hypercorn==0.16.0
hyperframe==6.0.1
hyperlink==21.0.0
icalendar==5.0.11
idna==3.6
incremental==22.10.0
inflection==0.5.1
iniconfig==2.0.0
isort==5.12.0
Jinja2==3.1.3
jsonschema==4.20.0
jsonschema-specifications==2023.12.1
jupyter_client==8.6.0
jupyter_core==5.7.1
jupyterlab_pygments==0.3.0
kombu==5.3.4
launchdarkly-eventsource==1.1.0
launchdarkly-server-sdk==9.1.0
lxml==5.1.0
Markdown==3.5.2
MarkupSafe==2.1.3
mistune==3.0.2
mixer==7.2.2
msgpack==1.0.7
multidict==6.0.4
nbclient==0.9.0
nbconvert==7.14.1
nbformat==5.9.2
newrelic==9.5.0
numpy==1.26.3
openai==1.7.1
packaging==23.2
pandas==2.1.4
pandocfilters==1.5.0
phonenumberslite==8.13.27
pillow==10.2.0
platformdirs==4.1.0
pluggy==1.3.0
premailer==3.10.0
priority==1.3.0
promise==2.3
prompt-toolkit==3.0.43
proto-plus==1.23.0
protobuf==4.25.2
psycopg==3.1.17
psycopg-binary==3.1.17
psycopg-pool==3.2.1
psycopg2==2.9.9
pyarrow==14.0.2
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycares==4.4.0
pycparser==2.21
pydantic==2.5.3
pydantic_core==2.14.6
pyfcm==1.5.4
PyGithub==2.1.1
Pygments==2.17.2
PyJWT==2.8.0
pymemcache==4.0.0
PyNaCl==1.5.0
pyOpenSSL==23.3.0
pyRFC3339==1.1
pytest==7.4.4
pytest-django==4.7.0
pytest-env==1.1.3
python-dateutil==2.8.2
python-frontmatter==1.0.1
python-slugify==8.0.1
pytz==2023.3.post1
PyYAML==6.0.1
pyzmq==25.1.2
redis==5.0.1
referencing==0.32.1
requests==2.31.0
rpds-py==0.16.2
rsa==4.9
schema==0.7.5
semver==3.0.2
serpy==0.3.1
service-identity==23.1.0
six==1.16.0
sniffio==1.3.0
socksio==1.0.0
soupsieve==2.5
SQLAlchemy==1.4.51
sqlalchemy-bigquery==1.9.0
sqlparse==0.4.4
stripe==7.11.0
text-unidecode==1.3
timeago==1.0.16
tinycss2==1.2.1
tornado==6.4
tqdm==4.66.1
traitlets==5.14.1
twilio==8.11.0
Twisted==23.10.0
txaio==23.1.1
typer==0.9.0
typing_extensions==4.9.0
tzdata==2023.4
uritemplate==4.1.1
urllib3==2.1.0
uvicorn==0.25.0
uvloop==0.18.0
vine==5.1.0
watchfiles==0.21.0
wcwidth==0.2.13
webencodings==0.5.1
whitenoise==6.6.0
wrapt==1.16.0
wsproto==1.2.0
XlsxWriter==3.1.9
yarl==1.9.4
zope.event==5.0
zope.interface==6.1
zstandard==0.22.0