Deploying Flask app on own Ubuntu Server Error - python

GOAL : I am trying to deploy my Flask app to make it public on the web. I have my own server which runs on Ubuntu 18.04
TUTORIAL : As it is the first time I am doing this, I am following this tutorial. All his steps are perfectly working for me except the last one. However, in this tutorial he used Linode and I use my own server so I directly code on my terminal
PROBLEM : In his last step after systemctl reload apache2 when I go on the my browser and type my ip address (found using ifconfig) that I put in webApp.conf (192.168.1.25) I get the following error :
ERROR LOGS : As asked I went into the error.log which outputs the following :
You can find the code here : https://pastebin.com/g2rzRUXE
POTENTIAL PROBLEMS: From what I understand I am having two issues :
Set the 'ServerName' directive globally to suppress this message . So I tried to solve it using this tutorial and I changed my private ip address to my public ip address (found on whatismyip.com) but when doing so I received the following error:
It does not seem to like my prints:
. Am I not allowed to keep prints
Please let me know how I could solve these problems or the other ones in the error log that I might not have seen.
I hope I was clear enough. If you need any additional info I can edit my question. I am running out of ideas so if you have any tips I would be grateful.

In the logs, I can read:
Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/2.7 configured -- resuming normal operations
So, you are using Python 2 instead of Python 3.
You need to install a mod_wsgi module compatible with Python 3.
Follow the instruction available here : https://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html
The following link can also help: https://stackoverrun.com/fr/q/12335951 (in French).

Related

How to setup a Local React App on Raspberrypi?

I'm having some troubles setting up my React App (front, with Python/PgSQL back) on my Pi after failing to build it from there (not enough memory), let me explain :
Before :
Everything was on the Pi : Python, Pg database, React App.
Use VSCode from Windows PC with SSH connexion to the Pi.
Run with npm start at raspberrypi.lan:3000 (or 192.168.0.14:3000, the Pi IP).
Everything was fine since i tried to improve it as i wanted to reach the app directly from
raspberrypi.lan
So is installed an Apache server then i followed some tutorials telling me that i just have to run npm run build and copy/paste the build folder in /var/www/html, what i did.
Awesome, it's working great !!
Now :
React code moved on Windows PC.
Use VSCode from Windows PC locally.
Dev (PC) run with npm start at localhost:3000.
Prod (Pi) run on Apache serveur at raspberrypi.lan.
Build with npm run build.
Transfert generated build folder by ftp to the Pi in /var/www/html
=> not really glamorous, if someone knows how to do it better….
Again, that's working good … except that …
When i call my Python API (remember, on the PI, at raspberrypi.lan:5000), i have two behaviors :
Dev (PC) :
Access to XMLHttpRequest at 'http://raspberrypi.lan/api/product/list' from origin 'http://localhost:3000' has been blocked by CORS policy
Prod (PI) :
You need to enable JavaScript to run this app.
I know what those mean but i don't know how to fix them properly.
You can notice that on Prod, the calls answers OK 200 but something seams missing.
If i add the API port i'm facing the CORS policy this time in Prod (too) :
Access to XMLHttpRequest at 'http://raspberrypi.lan:5000/api/product/list' from origin 'http://raspberrypi.lan' has been blocked by CORS policy
So here i am asking you :
How to setup those babies so i can reach the API from both PC and Pi sides ?
Thanks in advance and sorry for my approximative english.
Well,
Especially thanks to this answer i used to fix it using flask_cors Python library and ending up with the exact same situation than the other user.

Running an opencv based python script on a remote server with ssh forwarding from my macbook gives me an error

I am trying to run a python script on a remote server, which includes displaying images. The image does not get displayed and I get an error Gtk-WARNING **: cannot open display:
I have checked posts where they suggest editing the flags in sshd_config and also setting the DISPLAY variable manually. But, none of that seems to be working for me.
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
XAuthLocation /usr/X11/bin/xauth
Running xclock or xeyes also gives me errors.
Edit: I used ssh -X and ssh -Y to ssh into the server, neither worked
Solution: Restart after installing XQuartz
After looking through multiple posts and trying to make it work, I realised that after installing XQuartz, the user is required to restart the machine. It allows to set the correct environment variables (like DISPLAY). It works for me now after having restarted.
Alternative
However, in case you face a similar problem, not stemming due to the restart issue, I found an alternate way as suggested in the following link:
https://uisapp2.iu.edu/confluence-prd/pages/viewpage.action?pageId=280461906

script timed out before returning headers openshift

I have a python application (webservice) hosted in Openshift but, a few days ago, the app don't work anymore. The log points to "[error] script timed out before returning headers" and I can't solve this.
Someone can help me?
The solution was remove the cartridge and install Python 2.6
Please log in to your openshift account and check whether your application and cartridges are up and running.
From the mod_wsgi FAQ:
Q: Why am I seeing the error message 'premature end of script headers'
in the Apache error logs.
A: If using daemon mode, this is a symptom of the mod_wsgi daemon
process crashing when handling a request. You would probably also see
the message 'segmentation fault'. See answer for question about
'segmentation fault' above.
This error message can also occur where you haven't configured Apache
correctly and your WSGI script file is being executed as a CGI script
instead.
It could also be possibly due to the application code hanging. This can be due to the use of third party Python modules which have a C extension component which does not work in Python sub interpreters.
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
Unfortunately OpenShift has a less than ideal mod_wsgi configuration and no ready ability to override the configuration nor the start up of Apache itself. At least not unless that have made significant changes since the last time I looked.

Arelle Xbrl validation - unable to start web service - socket error 10013

I'm using the Arelle project to implement validation of my Xbrl files.
http://arelle.org/documentation/api-web-services/
When i try to start the webserver that i can call from my code i receive following error.
Been looking up how to fix this and it all points to disabling my antivirus. Got it disabled and i still get this error. Arelle is a Python project
This should start a webservice that i can reach on www.localhost:8082/rest/xbrl
Appearently this was an issue with the previous release of the project.
I installed the latest version 2013-07-25 and no longer had this socket error

Why does django jython connection to a MySQL database give a "Communication Link Failure"?

I'm trying to convert a django / cPython app to run as a Tomcat WAR using Jython. We are using a mysql database (MySQLdb in cPython / mysql-connector-java-5.1.15-bin.jar in jython). I have changed the DATABASE_ENGINE between the two configurations. The app runs great with cPython (after I disabled SELinux limitations on http connections to a database). The front page, images, and static content work in the jython. However, when I request a page that hits the database, it seems to hang for a while, then returns with:
Communications link failure
The last packet sent successfully to
the server was 0 milliseconds ago. The
driver has not received any packets
from the server. [SQLCode: 0],
[SQLState: 08S01]
Has anyone seen this before? I don't see any recent discussions of this type or problem. I'm using django 1.2.5, jython 2.5.2. I've tried running the Java app under Fedora (jre-1.6.0-openjdk.x86_64) and Windows (Java(TM) SE Runtime Environment (build 1.6.0_23-b05)). Same behavior. I've also tried both mysql-connector-java-5.1.15-bin.jar (the latest version) and mysql-connector-java-5.1.10-bin.jar ("extensively tested" according to http://packages.python.org/django-jython/database-backends.html). None of the various configurations affect the behavior.
How can I solve it or where should I look next?
I found the mistake. In hindsight, it's obvious. I made a type-o in the IP address of the database server, but only in the configuration file on the jython branch. As a result, the Jython instance hung while the cPython instance didn't. Found the error when I merged the two into a single settings.py (using "if os.name=='java'" to make the necessary jython changes.
So . . . What's the correct protocol here? Should I delete the question or leave it up in case someone else makes the same type of mistake I did?

Categories