I am trying to follow the tutorial on read the docs for Django Channels. In the settings.py file I am trying to change the inmemory BACKEND to the redis backend with the following code:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [("localhost", 6379)],
},
"ROUTING": "chan.routing.channel_routing",
},
}
However, the moment I do this, the console which is running the runserver command shows the following error:
ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
How can I fix this?
Please make sure if redis is installed on your system and it is running.
To check if redis is running use
redis-cli
then it will take you to redis console, then if you type ping it will return PONG if redis is running or not.
If you don't have redis in your system, please visit Redis Quick Start.
For Mac OS X: Go to terminal and type brew install redis.
This is worked for me:
redis-server
That's simple
Related
I've been working on a react app and I wanted to get hot re-loading going so I set up a webpack dev server. It's working great. It runs on localhost:8080 and the hot re-loading works perfectly.
Great, now I just need to set up a proxy to route requests from 8080 to my flask server running on 5000 right?
Cool so I added a proxy field to my webpack.config.js
27 devServer: {
28 static: './static/dist',
29 proxy: {
30 '/': 'http://localhost:5000',
31 secure:false,
32 }
33 },
But when I re-run npm run start
"start": "webpack serve --open --mode=development"
I get all of these connection refused errors. My flask is up and running fine and I can query the api routes directly and have data be returned.
[webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/all_users to http://localhost:5000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
I followed the URL and the only advice there was that this error usually occurs when the external system is down. Since mine isn't, I'm pretty confused.
Any help would be greatly appreciated.
I have no idea why but changing 'http://localhost:5000' to 'http://127.0.0.1:5000' solved my problem.
If anyone knows I'd still be curious why this fixed it. I can go to 'http://localhost:5000' in my browser and query my backend just fine.
hello I am working on chatting app with django channels works perfectly in localhost but once I used redis and deployed to heroku I can't send anymessage the websocket always close,
my settings.py
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
},
},
}
I am using redis and postgresql addons,
and my Procfile is like this
web: daphne myproject.asgi:application --port $PORT --bind 0.0.0.0 -v2
worker: python manage.py runworker --settings=myproject.settings -v2
the error from heroku logs --tail
2022-01-07T23:33:49.877754+00:00 app[web.1]: raise InvalidChannelLayerError(
2022-01-07T23:33:49.877754+00:00 app[web.1]: channels.exceptions.InvalidChannelLayerError: ROUT
ING key found for default - this is no longer needed in Channels 2.
2022-01-07T23:33:49.877914+00:00 app[web.1]: 2022-01-07 23:33:49,877 INFO failing WebSocket
opening handshake ('Internal server error')
2022-01-07T23:33:49.878083+00:00 app[web.1]: 2022-01-07 23:33:49,878 WARNING dropping connecti
on to peer tcp4:10.1.83.62:25575 with abort=False: Internal server error
2022-01-07T23:33:49.878720+00:00 app[web.1]: 2022-01-07 23:33:49,878 DEBUG WebSocket closed
for ['10.1.83.62', 25575]
why it works perfectly in my localhost because I am using only this
CHANNEL_LAYERS = {
"default": {
"BACKEND": 'channels.layers.InMemoryChannelLayer'
}
}
It's disabled on Heroku.
As it's mentioned in docs, you shouldn't use it in production:
In-memory channel layers operate with each process as a separate layer. This means that no cross-process messaging is possible. As the core value of channel layers is to provide distributed messaging, in-memory usage will result in sub-optimal performance, and ultimately data-loss in a multi-instance environment.
So you have to come up with a Redis solution.
I am getting the below error after I deployed my website on heroku.
Error 111 connecting to 127.0.0.1:6379. Connection refused.
Request Method: POST
Request URL: https://website.herokuapp.com/account/register
Django Version: 3.2.8
Exception Type: OperationalError
Exception Value:
Error 111 connecting to 127.0.0.1:6379. Connection refused.
Exception Location: /app/.heroku/python/lib/python3.8/site-packages/kombu/connection.py, line 451, in _reraise_as_library_errors
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.8.12
Python Path:
['/app',
'/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python38.zip',
'/app/.heroku/python/lib/python3.8',
'/app/.heroku/python/lib/python3.8/lib-dynload',
'/app/.heroku/python/lib/python3.8/site-packages']
Server time: Sat, 11 Dec 2021 21:17:12 +0530
So basically my website has to send email regarding otp, after registration and also some contract related emails. These email are neccessary to be sent hence can't be avoided. I posted a question earlier here regardig how to minimize the time that sending emails takes so that the user doesn't have to wait the entire time. I was suggested to use asynchronous code for this. So i decided to use celery for this. I followed the youtube video that taught how to use it.
Now after I pushed the code in the website I am getting this error. I am beginner andd have no idea how to rectify it. Please suggest me what shoul I do. Below are the details and configurations.
settings.py
CELERY_BROKER_URL = 'redis://127.0.0.1:6379'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379'
CELERY_ACCEPT_CONTENT =['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SELERLIZER = 'json'
requirements.txt
amqp==5.0.6
asgiref==3.4.1
billiard==3.6.4.0
celery==5.2.1
click==8.0.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
colorama==0.4.4
Deprecated==1.2.13
dj-database-url==0.5.0
Django==3.2.8
django-ckeditor==6.1.0
django-filter==21.1
django-js-asset==1.2.2
django-multiselectfield==0.1.12
dnspython==2.1.0
As I mentioned I am beginer, please suggest me a detailed ans as to how I can recctify this error.
Here's the problem:
CELERY_BROKER_URL = 'redis://127.0.0.1:6379'
Redis won't be running on your local dyno. You'll have to run it somewhere else and configure your code to connect to it. A common choice is to run Redis via an addon:
Once you’ve chosen a broker, create your Heroku app and attach the add-on to it. In the examples we’ll use Heroku Redis as the Redis provider but there are plenty of other Redis providers in the Heroku Elements Marketplace.
If you choose to use Heroku Redis, you'll be able to get the connection string to your instance via the REDIS_URL environment variable:
Heroku add-ons provide your application with environment variables which can be passed to your Celery app. For example:
import os
app.conf.update(BROKER_URL=os.environ['REDIS_URL'],
CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
Your Celery app now knows to use your chosen broker and result store for all of the tasks you define in it.
Other addons will provide similar configuration mechanisms.
All quoted documentation here, and most links, come from Heroku's Using Celery on Heroku article. I suggest you read the entire document for more information.
I am using Django-channels to connect to the server, but it always show the error like this:
reconnectwebsockets.js WebSocket connection to 'ws:xxx' failed:
Error during WebSocket handshake: Unexpected response code: 200
Also, I am using docker, this may be a issue of docker container configuration?
Any ideas what could be possibly wrong?
Question details
Hello, did you try to use channels library? It will give you same powerful as Django-channels one. Here you can find necessary documentation for it.
I recommend you use it because it is give you more flexibility then Django-channels one.
Channels library
Quick start
You can read how to work with it at Tutorial.
Errors and solutions
Unexpected response code: 200 (or other code XXX) (solved):
Be sure you include your application and channels via settings (mysite.settings) and use asgi application:
INSTALLED_APPS = [
'channels',
'chat',
...
]
...
ASGI_APPLICATION = "mysite.asgi.application"
Be sure you use channel layers (mysite.settings).
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer',
},
}
According Documentation you should use database for production, but for local environment you may use channels.layers.InMemoryChannelLayer.
Be sure you run asgi server (not wsgi) because you need asynchronous behaviour. Also, for deployment you should use daphne instead of gunicorn. daphne is included in channels library by default, so you don't need to install it manually.
Basic run server will look like (Terminal):
daphne -b 0.0.0.0 -p $PORT mysite.asgi:application
where $PORT is specific port (for UNIX system is 5000). (That format used for heroku application, you can change it manually).
Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR and same errors with using https connection (solved):
Difference between ws and wss?
You may think about to use your server via wss protocol:
replace ws://... with wss://... or use following template in your html (chat/templates/chat/room.html):
(window.location.protocol === 'https:' ? 'wss' : 'ws') + '://'
Hope this answer is useful for channels with Django.
I installed PostgreSQL(9.0.7) from EnterpriseDB on OS X 10.6. However, when I do a simple
$ psql -U postgres
I get this
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I am using it with Django. I tried changing the host variable in settings.py to
'HOST': '/tmp'
but I am still getting the same error message when I do a syndb. Any ideas? Thank you.
In my postgresql.conf
listen_addresses = '*'
port = 5432
unix_socket_directory = '/var/pgsql_socket/'
Edit:
I got it working. For some reason installed the newer version 9.1.3 and that error went away. I also got some help from a cheat sheet for PostgreSQL(http://od-eon.com/blogs/calvin/postgresql-cheat-sheet-beginners/)
Have you started the database cluster? You should be able to tell by running the command
ps auwwx|grep postg
You should see several postgresql processes. If you do not, you need to start the database server.
http://www.postgresql.org/docs/9.0/static/server-start.html