Comments (6)
Released in 0.13.1
.
from daphne.
Could you provide a way to reproduce, preferably using curl
? Usually leaving off the Upgrade header results in a 200 OK
, and the error you've posted a stack trace for looks like the __init__
hasn't been run, which is... odd.
from daphne.
I'm happy to debug this further so let me know what I can do. To be explicit: This happens when nginx
isn't configured with the Upgrade-header-settings; in both cases the curl
command is identical and does contain the Upgrade-header.
I can reproduce it with this minimal setup:
Terminal 1
$ mkdir /tmp/channels
$ cd /tmp/channels
$ virtualenv --python /usr/bin/python3 virtual
$ . virtual/bin/activate
$ pip install django channels asgi_redis
$ django-admin startproject testing
$ vim testing/testing/settings.py
[add channels to INSTALLED_APPS + CHANNEL_LAYERS, SEE BOTTOM]
$ vim testing/asgi.py
[ADD asgi.py, SEE BOTTOM]
$ vim testing/testing/routing.py
[EMTPY ROUTES, SEE BOTTOM]
$ vim /etc/nginx/sites-enabled/mysite.conf
[SEE BOTTOM]
$ cd testing
$ PYTHONOPTIMIZE=1 daphne -p 16661 asgi:channel_layer
Terminal 2
experience@reaper:~$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: XXX==' -H "Host: experience.ytec.nl" -H "Origin: http://www.websocket.org" 'http://experience.ytec.nl/websocket/'
HTTP/1.1 502 Bad Gateway
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 27 Jun 2016 21:36:18 GMT
Content-Type: text/html
Content-Length: 181
Connection: keep-alive
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>
(That is Daphne crashing)
Terminal 1
^C
$ vim /tmp/channels/virtual/lib/python3.4/site-packages/dhne/http_protocol.py +107
[comment log line out]
$ PYTHONOPTIMIZE=1 daphne -p 16661 asgi:channel_layer
Terminal 2
experience@reaper:~$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: XXX==' -H "Host: experience.ytec.nl" -H "Origin: http://www.websocket.org" 'http://experience.ytec.nl/websocket/'
HTTP/1.1 400 HTTP Connection headers do not include 'upgrade' value (case-insensitive) : close
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 27 Jun 2016 21:37:33 GMT
Transfer-Encoding: chunked
Connection: keep-alive
testing/testing/settings.py
:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channels',
]
CHANNEL_LAYERS = {
'default': {
'ROUTING': 'testing.routing.channel_routing',
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
}
}
}
testing/asgi.py
:
import os
from channels.asgi import get_channel_layer
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testing.settings')
assert not __debug__ #Make sure the server is configured for not running in debug mode. Just enable optimization to set __debug__ to false.
channel_layer = get_channel_layer()
testing/routing.py
:
channel_routing = []
/etc/nginx/sites-enabled/mysite.conf
:
server {
listen 80;
server_name experience.ytec.nl;
location /websocket/ {
proxy_pass http://localhost:16661;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
}
}
from daphne.
Thanks for the curl command - running it directly against daphne also helped reproduce the error, as it had a bad Key
which went down the same path.
I've pushed a fix to master; if you could confirm it works, I'll make a release.
from daphne.
It works like a charm.
from daphne.
I have the same problem as well. Tested the fix, seems good.
from daphne.
Related Issues (20)
- issuse when i using daphe in my django app with streaminghttpresponse HOT 7
- Can daphne run WSGI apps? HOT 6
- Does daphne have a file for initialization?
- Requests with Transfer-Encoding: chunked have no content HOT 14
- StreamHttpResponse with sync operations break in Daphne HOT 5
- Memory usage: Daphne loading all the file in memory (POST request) HOT 7
- Text streaming buffered issue
- Implement WebSocket Denial Response extension HOT 8
- [feature request] trailing headers HOT 1
- Add support for Python 3.12
- DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13 HOT 1
- Daphne with self signed ssl HOT 2
- Daphne allows invalid characters within header names HOT 5
- Unix File Socket Argument HOT 12
- TypeError: object HttpResponse can't be used in 'await' expression HOT 3
- add support for --proxy-headers and friends in runserver HOT 4
- fd_endpoint.py is not properly installed HOT 7
- python manage.py runserver not working HOT 5
- Daphne - Twisted custom cipher list using set_cipher method HOT 3
- --noasgi won't serve static files HOT 1
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 daphne.