Open jessielaf opened 4 years ago
Hmm, that line doesn't seem to be in the codebase. If it's from a stack trace, do you have more of it?
Sorry, I forgot to add the traceback.
Traceback (most recent call last):
File "C:\Users\Jessie\AppData\Local\pypoetry\Cache\virtualenvs\effe-S2ztncmJ-py3.7\lib\site-packages\daphne\http_protocol.py", line 179, in process
"server": self.server_addr,
AttributeError: 'NoneType' object has no attribute 'value'
I also use WebSockets and have a custom middleware I will share. Maybe it has something to do with that. The websocket never gives this error by the way.
application = ProtocolTypeRouter(
{
"http": URLRouter(
[
url(
r"^events/(?P<channel>\w+)/",
TokenAuthMiddleware(URLRouter(django_eventstream.routing.urlpatterns)),
),
url(r"", AsgiHandler),
]
),
"websocket": TokenAuthMiddleware(URLRouter([path("schedule/", ScheduleConsumer),])),
}
)
class TokenAuthMiddleware:
def __init__(self, inner):
self.inner = inner
def __call__(self, scope):
close_old_connections()
headers = dict(scope["headers"])
if b"cookie" in headers:
cookie = SimpleCookie()
cookie.load(headers[b"cookie"].decode())
authentication = JWTAuthentication()
validated_token = authentication.get_validated_token(cookie.get("Authorization").value)
scope["user"] = authentication.get_user(validated_token)
return self.inner(scope)
I wonder if this is a dependency versions problem.
Here's what is used by the chat example in this repo: https://github.com/fanout/django-eventstream/blob/master/examples/chat/requirements.txt
You could try pinning to the same versions and seeing if it works. I know in the past there have been issues with asgiref/channels/daphne being out of alignment.
The only difference I have is Django at 3.0.4 but these problems were occurring before me upgrading Django
Do you have any idea why this is happening?
No idea. A reproducible example would help. Maybe apply your middleware to the chat example?
I don't know if this is the right place. But I have problems with connecting to the SSE endpoint. Sometimes it works sometimes it doesn't. I get this error
Do you maybe know what is going on and how I can fix it?