GithubHelp home page GithubHelp logo

Sessions not working about channels HOT 8 CLOSED

django avatar django commented on July 24, 2024
Sessions not working

from channels.

Comments (8)

andrewgodwin avatar andrewgodwin commented on July 24, 2024

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.

deconduino avatar deconduino commented on July 24, 2024

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.

andrewgodwin avatar andrewgodwin commented on July 24, 2024

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.

andrewgodwin avatar andrewgodwin commented on July 24, 2024

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.

deconduino avatar deconduino commented on July 24, 2024

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.

deconduino avatar deconduino commented on July 24, 2024

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.

django/daphne#2

from channels.

andrewgodwin avatar andrewgodwin commented on July 24, 2024

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.

deconduino avatar deconduino commented on July 24, 2024

Yeah that looks good now, sessions and transfer_user are working as expected.

Thanks

from channels.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.