I am trying to debug a flask app in Pycharm debugger that runs using Docker containers on my Ubuntu 20.04.4LTS.
I added the following piece of code for that purpose in my extensions.py.
pydevd_pycharm.settrace(
"host.docker.internal",
port=9000,
stdoutToServer=True,
stderrToServer=True,
suspend=False,
)
However, I am getting the error: Could not connect to host.docker.internal: 9000. when I run docker-compose -f up -d --build --remove-orphans. My /etc/hosts does not specifcy any mapping for host.docker.internal either which might have caused the issue.
I tried changing host.docker.internal to localhost but no luck. Below is my debug config for python debug server. Anyone help please!
I have deployed a flask application with uwsgi and nginx
The following is the .ini file for uwsgi
[uwsgi]
;module = name of file which contains the application object in this case wsgi.py
LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib
chdir=/home/ansible/apps/payment_handler
module = wsgi:application
;tell uWSGI (the service) to start in master mode and spawn 5 worker *processes* to serve requests
master = true
processes = 5
;a socket is much faster than a port, and since we will be using nginx to exppose the application this is better
socket = 0.0.0.0:8001
vaccum = true
die-on-term = true
When I run this from the command line like so
uwsgi --ini payment_app.ini
It works !
However I would like to run the application using a service, the following is the service file
[Unit]
Description=uWSGI instance to serve service app
After=network.target
[Service]
User=root
WorkingDirectory=/home/ansible/apps/payment_handler
Environment="PATH=/home/ansible/apps/payment_handler/env/bin"
ExecStart=/home/ansible/apps/payment_handler/env/bin/uwsgi --ini payment_app.ini
[Install]
WantedBy=multi-user.target
However it does not work because it cannot find the libs for cx_oracle
I have it set in my bashrc file
export LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib
However since the service file does not use this to load it's env variables it seems to not find it
Error log
Jun 17 09:58:06 mau-app-036 uwsgi: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
I have tried setting it in the .ini file (as seen above)
LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib
I have also tried setting it in my init.py file using the os module
os.environ['LD_LIBRARY_PATH'] = '/usr/lib/oracle/18.3/client64/lib'
Both to no avail, any help would be great thanks Centos 7 btw
Problems like this are why the Instant Client installation instructions recommend running:
sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > \
/etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig
This saves you having to work out how & where to set LD_LIBRARY_PATH.
Note that the 19.3 Instant Client RPM packages automatically runs this for you. Some background is in the Instant Client 19c Linux x64 release announcement blog.
Heroku seems to have a dependency on Gunicorn when it comes to Python / Django apps. Gunicorn is not supported on Windows. Has anybody had success or know of a work around?
My app runs fine but not under Heroku or Heroku local
Error:
...site-packages\gunicorn\util.py", line 9, in <module>
import fcntl
ModuleNotFoundError: No module named 'fcntl'
Exited with exit code null
It seems unfair to blame Heroku for this. Gunicorn doesn't support Windows. Heroku has nothing to do with Windows.
There are other WSGI web servers that may work. For example, uWSGI has documentation for running on Heroku.
A quick summary:
Make sure that uwsgi and werkzeug are in your requirements.txt or Pipfile / Pipfile.lock and that these files are tracked by Git
Create and track a uwsgi.ini file containing something like
[uwsgi]
http-socket = :$(PORT)
master = true
processes = 4
die-on-term = true
module = werkzeug.testapp:test_app
memory-report = true
making sure to set the module appropriately for your application.
Update your Procfile to contain
web: uwsgi uwsgi.ini
Make sure it works with heroku local, then push to Heroku.
I've built a Django project that works, even after I freeze it using Cx_Freeze and Py2exe.
Now I'm trying to set up the project for distribution, which requires a real webserver. I'm going for Gunicorn (will add Nginx once it works). I managed to run the Gunicorn server properly through the command line using :
gunicorn wsgi:application
However, I need to be able to run the server from my Python script, as the server is ment to be localhost. Gunicorn used to be shipped with a command 'run_gunicorn' designed for Django, but this command is now deprecated.
I tried understanding the following method :
How to use Flask-Script and Gunicorn
But I can't figure out how to make it work with Django.
The following doesn't work:
from django.core.wsgi import get_wsgi_application
from gunicorn.app.base import Application
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = get_wsgi_application()
Application().run(application)
Could someone tell me how to start the gunicorn server from my Python script ?
Ubuntu 12.04, nginx 1.2.0, uwsgi 1.0.3.
I start uwsgi with the following command:
uwsgi -s 127.0.0.1:9010 -M -t 30 -A 4 -p 4 -d /var/log/uwsgi.log
On each request nginx replies with 502 and uwsgi writes to log the following line:
-- unavailable modifier requested: 0 --
Original answer
For Python 2 on Ubuntu 11.10, using upstart, install the python plugin for uWSGI with apt-get install uwsgi-plugin-python and if you're using an ini file to configure your uWSGI app, then add plugins = python to the [uwsgi] section and it should solve this problem.
Edit: Updated for Python 3 and Ubuntu 17.10
For Python 3 on Ubuntu 17.10, using systemd, install the python plugin for uWSGI with apt-get install uwsgi-plugin-python3 and if you're using an ini file to configure your uWSGI app, then add plugins = python to the [uwsgi] section and it should solve this problem.
For more information on getting started with python/uWSGI apps, including how to configure them using an ini file then please take a look at this handy guide
Solved by installing uwsgi-plugin-python3 plugin and adding --plugin python3 option to uwsgi start command
Im starting uwsgi from upstart on Ubuntu. I solved the problem by running apt-get install uwsgi-plugin-python, and then adding plugins=python to my application.ini in /etc/uwsgi/applications-available.
from http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html, "To route requests to a specific plugin, the webserver needs to pass a magic number known as a modifier to the uWSGI instances. By default this number is set to 0, which is mapped to Python."
I'm using 9 for a bash script and it's working. the numbers and their meanings are on this page: http://uwsgi-docs.readthedocs.org/en/latest/Protocol.html
in my nginx configuration:
location ~ .cgi$ {
include uwsgi_params;
uwsgi_modifier1 9;
uwsgi_pass 127.0.0.1:3031;
}
Modify your ini file by added plugins line.
[uwsgi]
plugins = python3
I'm using Ubuntu 18.04 with Python 3. Below is the exact config I used to get it working.
You must have the Python 3 uWSGI plugin installed:
apt install uwsgi-plugin-python3
Your Nginx site configuration should point to your uWSGI socket. Make sure the port matches the configuration in the later steps.
location / {
uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;
}
Reload the Nginx config to reflect the changes you just made:
systemctl reload nginx
You can use command-line arguments or an ini file for configuration. I created uwsgi.ini. Make sure the socket address matches your nginx config.
[uwsgi]
socket = 127.0.0.1:9090
chdir = /var/www
processes = 4
threads = 2
plugins = python3
wsgi-file = /var/www/app.py
My app.py just has a basic example:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/plain')])
return [b"Hello World!"]
Now start the uWSGI server from the command line:
uwsgi uwsgi.ini