Comments (16)
Even i run into the same issue when using rest framework along with the websocket
from channels.
Yeah, I'm looking into an emulation layer to prevent this; hopefully I can provide a StringIO object with the right information for DRF.
from channels.
@andrewgodwin Hey, any update on this ? I'd be happy to help in anyway if there's something I can do !
from channels.
Well, I just finished finalising how to transmit request bodies in ASGI, which was the underlying blocker - there's no way to provide the body emulation otherwise. Now that's done, fixing up the Request object to actually take those bodies is next, followed by things like this that are emulation layers.
You can take a stab if you like, but I have it half-written already, just need to get it done and tested :) What would be useful is if you could work out what DRF is trying to use _stream for; I'd like to make sure it's just trying to access the raw request body.
from channels.
@andrewgodwin OK! Ive just read the ASGI spec and understand what you exactly mean. I will take a stab into DR..
from channels.
@andrewgodwin i've been playing around with channels last couple of days, really great work, thanks !
regarding the _stream
issue, it does not exist when using separate servers (ie not using --accept-all
) for HTTP and WS. Everything seems to work as intended.
PS : I've seen you have changed the current 0.8
approach and are now using andrewgodwin/daphne
as the server. 👍
from channels.
Yup - running WSGI and WS seperately will always be an option, as WSGI is just more mature and stable and it's silly not letting you use it (and likely slightly more efficient as it's not double-transforming requests).
Only downside is that it means no simultaneous websocket support - you have to tell your webserver to route a prefix - but that's not the worst thing. I'll be adding some diagrams into the real docs about this to show the different options.
from channels.
@andrewgodwin just posting an update here. I was previously wrong, everything is not working as intended, but I have better info:
- DRF tries to access
_stream
while trying to parse request bodies (POST/DELETE requests) - Even if the request does have a body - error is not raised till you access
request.data
TL:DR from my testing (v0.8
)
Works
- request.META
- headers
- query_params
Doesn't Work
- request.data
from channels.
Yes, I suspect that I need to implement read()
and other methods on the new WsgiRequest class.
from channels.
Is it possible to implement this as a patch against v0.8, or does it have to wait for ASGI to settle down in the master branch? I'm trying to use channels with DRF right now.
I'll take a look and try to at least develop a failing test. I don't know if I'll be able to do more than that, or if it makes sense to.
from channels.
Nah, 0.8 doesn't have HTTP body transport at all. Once I get some time I should be able to get a 0.9 out; ASGI is pretty settled already and seems to work alright in practice, just needs a bit of polish so it's useable out of the box.
from channels.
Do you have a sense of when that might be? Not trying to push. 😉
from channels.
Afraid I can't commit to dates; I'm not working on this in a paid capacity yet, so it's all personal time as and when it comes up.
from channels.
A comment on django.http.request.HttpRequest.read()
says
# File-like and iterator interface.
#
# Expects self._stream to be set to an appropriate source of bytes by
# a corresponding request subclass (e.g. WSGIRequest).
# Also when request data has already been read by request.POST or
# request.body, self._stream points to a BytesIO instance
# containing that data.
It looks to me like setting self._stream = BytesIO(self._body)
in AsgiRequest.__init__()
might satisfy that?
from channels.
Yup, that's the plan. Just need to make sure the whole thing works end-to-end properly and correctly encodes/decodes; it's all still slightly experimental.
from channels.
OK, stream is now implemented.
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 9
- Django Channels Memory Leak on every message or connection HOT 27
- WARNING daphne.server ASGIStaticFilesHandler WebRequest took too long to shut down and was killed HOT 4
- 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.