Closed
Description
- GraphQL AioWS version: graphql_ws 0.4.4
- Python version: Python 3.8.10
- Operating System: Ubuntu
Description
I'm running Daphnie with asgi.py but when I try to test it with wscat
it gives 403 (access denied) error in logs in daphne servers.
What I Did
asgi.py
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import OriginValidator
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "company.settings.base")
from graphql_ws.django.routing import websocket_urlpatterns
# This configures route to /subscriptions.
# https://github.com/graphql-python/graphql-ws/blob/474f733761c04f39ccd9367190b5a85a5033fc2c/graphql_ws/django/routing.py#L20
application = ProtocolTypeRouter({
"websocket": URLRouter(websocket_urlpatterns),
})
settings.py
# ...
INSTALLED_APPS = (
# ...
'channels',
"graphql_ws.django",
'graphene_django',
# ...
)
GRAPHENE = {
'SCHEMA': 'schema.schema',
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
# https://docs.graphene-python.org/projects/django/en/latest/subscriptions/#subscriptions
"SUBSCRIPTION_PATH": "/subscriptions",
}
ASGI_APPLICATION = 'app.asgi.application'
# ...
Then I run daphne -p 8001 app.asgi:application -v 2
In other console, I ruh websocket commands with wscat -c ws://localhost:8001/subscriptions
it was giving me the logs (errors)
2022-01-21 12:23:10,555 INFO Listening on TCP address 127.0.0.1:8001
127.0.0.1:54400 - - [21/Jan/2022:12:23:16] "WSCONNECTING /subscriptions" - -
2022-01-21 12:23:16,476 DEBUG Upgraded connection ['127.0.0.1', 54400] to WebSocket
2022-01-21 12:23:16,476 INFO failing WebSocket opening handshake ('Access denied')
2022-01-21 12:23:16,477 WARNING dropping connection to peer tcp4:127.0.0.1:54400 with abort=False: Access denied
2022-01-21 12:23:16,477 DEBUG WebSocket ['127.0.0.1', 54400] rejected by application
127.0.0.1:54400 - - [21/Jan/2022:12:23:16] "WSREJECT /subscriptions" - -
2022-01-21 12:23:16,477 DEBUG WebSocket closed for ['127.0.0.1', 54400]
127.0.0.1:54400 - - [21/Jan/2022:12:23:16] "WSDISCONNECT /subscriptions" - -
wscat
> root # wscat -c ws://localhost:8001/subscriptions
error: Unexpected server response: 403
Seems like authorization error. I've tried with
OriginValidator(URLRouter(websocket_urlpatterns), ["*"]),
but no luck. I think it's related to graphql-ws configurations that I set up or maybe some steps I'm missing?
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
Metadata
Metadata
Assignees
Labels
No labels