django channels on railway no supported websockets library detected - django

I'm migrating my portfolio projects from heroku to railway, they're all asgi and use django channels and redis. They work fine on heroku, but not on railway. All of my api endpoints are working and connecting to postgres. But when I got to the chat part of my application it won't connect. The deploy logs in railway say the following:
[2022-11-11 02:19:58 +0000] [11] [WARNING] Unsupported upgrade request.
[2022-11-11 02:19:58 +0000] [11] [WARNING] No supported WebSocket library detected. Please use 'pip install uvicorn[standard]', or install 'websockets' or 'wsproto' manually.
I've double checked my requirements.txt and updated my packages. I've uninstalled and reinstalled locally ( I made sure to use uvicorn[standard] which supports sockets).
I've used railway cli to manually pip install install the packages and none of the above has worked. I'm not using any heroku buildpacks.
Any body else having this issue?

Related

DigitalOcean Droplet not serving django app with python runserver command

i know i have seen similar questions on the issue but most of them seemed to be solved by allowing the port 8000 by using the command sudo ufw allow 8000. i have tried that but it is still not displaying when i visited my droplet_ipaddress:8000 link. i followed the official tutorials https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-22-04.
SYSTEM INFORMATION
OS = Ubuntu 22.04 LTS
Python = 3.10
Django = 4.0.4
the only difference with my work and the project process is that i did not build an dummy django project on my digitalocean vps rather i use git to clone my project repo and did the neccesary dependency installing using pip. Has anyone encountered the same problem and is there any solution.
when ever i ran python manage.py runserver 0.0.0.0:8000
the output is shown below as expected … but my page doesn't not display as expected
Performing system checks...
System check identified no issues (0 silenced).
You have 33 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): account, accounts, admin, ads, auth, chat, contenttypes, notification, payments, report, sales, sessions, sites, socialaccount.
Run 'python manage.py migrate' to apply them.
May 10, 2022 - 11:41:04
Django version 4.0.4, using settings 'ma_mall.settings.production'
Starting ASGI/Channels version 3.0.4 development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
when i visit the page its says
searching for the allowed port on the system gave this
which clearly shows the the port is now allowed to serve the app
In Digital Ocean, it is possible that you have a second firewall enabled that can be configured directly on the platform. You can find it under Droplet>Networking. Check if a firewall exists and adjust it for your port. Since two firewalls are a bit cumbersome and pointless, I would recommend using only the Digital Ocean firewalls and disabling ufw permanently via ufw disable.

chat socket (web socket)is closing unexpectedly (django-channels)?

console image
i have gone through as it mentioned in the docs(channels) it worked fine until i pasted the code of channel_layers in settings.py
i installed all the specifications mentioned in channel_layers
ASGI_APPLICATION = 'mysite.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
why is my chat_server closing unexpectedly
First of all check wheather redis is running in your machine or not.
if not google it you will find.
->check these points wheather you had done correctly:
1.check wheather the data you send to sockets are in string format.
2.check the json you are sending to sockets is correctly parsed.
3.similarly check the data received from sockets is correctly parsed.
if you want to automatically reconnect to sockets use
https://github.com/joewalnes/reconnecting-websocket copy the js file there and place the script in your html and then replace WebSocket to ReconnectingWebSocket
This problem arise due to reddis channel not working at backend after configuring in the setting.py you should start the reddis channel
if you are using docker then try this
docker run -p 6379:6379 -d redis:5
if u have connections problem with django-channels,
first install channels --> pip install -U channels
after installing channels add 'channels' install app in your setting.py file and follow these docs to install channels properly in your django project
--> https://channels.readthedocs.io/en/latest/installation.html
after installing django channels now install channels-redis in your django project,
first step is to install redis in your local machine , but install redis 5 or above
follow installing steps to install redis server in ubuntu and download redis direct if you use windows.
download plus installing steps in this link--> https://redis.io/download
after istalling redis in your local machine install channels-redis in your django project
--> pip install channels-redis==2.4.2
this is latest solution of django channels connection problem with redis , i hope this will help you
I had similar problem .
My websocket connect and disconnect immediately ,
Although Redis was installed,
The problem was with the Redis version.
Your Redis version must be greater than five

uWSGI command not found

Background:
I am in the process of deploying a Django site and from my understanding and research, I needed to get a web server, a WSGI protocol interface to actually run said python code and 'communicate' with it, and lastly a reverse proxy server to tie the two together and pass HTTP requests through the pipeline to Django. (By virtue of my install method, mod_wsgi is not an option thanks to EasyApache4 and cPanel so I cannot use the mod_wsgi sockets method)
My problem:
I have organized an apache 2 hosting server and managed to install mod_proxy and mod_proxy_uWSGI using the EasyApache4 auto installer. From what I understand, now I need to set up the proxy system to relay HTTP requests through mod_proxy_uWSGI which doubles up and also runs my Django site, however, I cannot access or configure mod_proxy_uWSGI. When I try using the following style command (sorry, I don't want my server URLs floating around the internet):
uwsgi --http :8000 --wsgi-file test.py
I get an error message:
bash: uwsgi: command not found
Am I missing something?
Thanks to a comment by [#dirkgroten]. To install UWSGI :
pip install uwsgi
After running pip install uwsgi, it's possible that uwsgi was installed someplace not on your PATH. IE, in my case, it got installed to:
/usr/local/opt/python-3.8.6/bin/uwsgi
I was able to fix this by adding a symlink:
sudo ln -s /usr/local/opt/python-3.8.6/bin/uwsgi /usr/bin/uwsgi
(This may be a terrible idea. It may be a much better idea to use a venv, but I'm following a tutorial that specifically told me to avoid using a venv.)
In my case, using Docker, I found the binary to be located in:
/home/webappuser/.local/bin
Adding to #ArtOfWarfare's answer, you can check where pip is installing your packages using this command.
▶ pip show uwsgi
Name: uWSGI
Version: 2.0.21
Summary: The uWSGI server
Home-page: https://uwsgi-docs.readthedocs.io/en/latest/
Author: Unbit
Author-email: info#unbit.it
License: GPLv2+
Location: /Users/username/Library/Python/3.9/lib/python/site-packages
Requires:
Required-by:
In my case, it is /Users/username/Library/Python/3.9/lib/python/site-packages. So the uwsgi binary will be present in /Users/username/Library/Python/3.9/bin/. Add this location to PATH and you should be good.

Openshift Bcrypt error

I have a python app deployed on openshift. For some weird reason, I keep getting internal server error. I checked my logs to see that it said cannot find module named flask-Bcrypt. However, when I ssh into the app and do a pip freeze, I see flask-bcrypt installed.

Failed to query Solr using '*:*': [Errno 111] Connection refused

Tried to integrate haystack 2.0.0-beta - solr with my django project for full text search, when i run the following
from haystack.query import SearchQuerySet
al = SearchQuerySet().all()
got an error
Failed to query Solr using '*:*': [Errno 111] Connection refused
How can i solve this issue?Thanks in advance.
Solr doesn't look to be running and you haven't given any details so:
Solr is a standalone process that needs to be started manually. Furthermore, it needs a servlet container to run within, normally jetty or tomcat which are both java based (discussion here and here). Depending on your machine, you need to install and start these before you get started with python or Django. If you are debian you can most likely do apt-get install solr-jetty and voila.
Once solr is installed, you need the bindings for python pysolr - pip install pysolr and django haystack pip install haystack==2.0.
There is a tutorial in the haystack documentation here, as well as a good blog post here about installing, starting and configuring the combination of solr, jetty, python and django.