Comments (8)
Ah, interesting - are you using Daphne or the WSGI adapter (and which versions, please)? This should be easy to fix once we find the source.
from channels.
Ah yes, I didn't think about checking Daphne. Not at my computer right now, but it was the latest pip version of everything.
from channels.
Alright, will see if I can replicate locally - last time I checked sessions and auth was working, though it's possible I screwed it up since then.
from channels.
Hmm, cookie based sessions work, that's what I had been testing before. The message content shouldn't decode the GET params, though - that's Django's job.
If you could paste an example of the message content you're seeing that would be great.
from channels.
Message content is below:
{u'reply_channel': u'!websocket.send.kWlVZObm', u'server': ['127.0.0.1', 8000], u'headers': {u'origin': 'http://localhost:8000', u'upgrade': 'websocket', u'accept-language': 'en-US,en;q=0.5', u'accept-encoding': 'gzip, deflate', u'sec-websocket-version': '13', u'connection': 'keep-alive, Upgrade', u'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', u'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0', u'host': '127.0.0.1:8000', u'sec-websocket-key': 'rzIzEE1o/Lys/bnIzLZHmg==', u'pragma': 'no-cache', u'cache-control': 'no-cache', u'sec-websocket-extensions': 'permessage-deflate'}, u'client': ['127.0.0.1', 51332], u'query_string': 'session_key=%5Bu%27f2ram92w1w7764yf2lg7oe8tft3ri5an%27%5D', u'path': '/', 'method': 'FAKE', u'order': 0}
Actual session key is f2ram92w1w7764yf2lg7oe8tft3ri5an
JS socket request is socket = new WebSocket("ws://127.0.0.1:8000/?session_key=f2ram92w1w7764yf2lg7oe8tft3ri5an");
Looking into it a bit more, it looks like the request.params
object being passed to Daphne is {u'session_key': [u'f2ram92w1w7764yf2lg7oe8tft3ri5an']}
So Daphne (ws_protocol.py) just url encodes the list part at that point:
query_string = urlencode(request.params).encode("ascii")
Is twisted what generates the request object from the websocket request?
from channels.
So twisted returns the url params as lists as per:
https://twistedmatrix.com/documents/8.2.0/api/twisted.web.http.Request.html
However the urllib encoding supports this using a doseq parameter: https://docs.python.org/2/library/urllib.html#urllib.urlencode
The solution to this is to update ws_protocol.py
in Daphne to use this:
query_string = urlencode(request.params).encode("ascii")
query_string = urlencode(request.params, doseq=True).encode("ascii")
I went to submit a pull request, but it looks like there already is one :) Should have checked that first.
from channels.
I really should have remebered to turn on notifications for the daphne repo! I've merged that PR and released the result as 0.9.3 - install it from pip and verify it fixes the issue, and close if it does!
from channels.
Yeah that looks good now, sessions and transfer_user
are working as expected.
Thanks
from channels.
Related Issues (20)
- OriginValidator could raise exception/log message for denied connections HOT 1
- Unable to collect code coverage when using `ChannelsLiveServerTestCase` HOT 14
- error in channel layer explanations HOT 2
- adding a check if group_name exists method for channel_layer HOT 1
- Small messages are getting concatenated HOT 2
- How can I change the schema in the database? HOT 1
- How to test send_json() contents when passing close=True HOT 2
- Handler declaration by decorator/annotation (in order to prevent potential method leaks) HOT 1
- django-q2 and django-channels together HOT 1
- Channel Layer's group_send() Not Working When Called From Django View HOT 3
- Add CORs middleware HOT 1
- Breakage in routing.py on django/main pre-5.1.
- Use Django async-native APIs where possible HOT 4
- Django Channels Memory Leak on every message or connection HOT 26
- WARNING daphne.server ASGIStaticFilesHandler WebRequest took too long to shut down and was killed HOT 1
- Use group_send() when group is empty HOT 1
- Session Data Corrupted HOT 1
- Error with send_json Function in AsyncJsonWebsocketConsumer HOT 6
- Getting TypeError: SSEConsumer() missing 2 required positional arguments: 'receive' and 'send'
- django.core.exceptions.SynchronousOnlyOperation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from channels.