I have used flask app for straming video via raspberrypi camera. The code i used for flask app is here:
https://blog.miguelgrinberg.com/post/video-streaming-with-flask
In local server it is doing video stream but not on my website.
I am using apache2 server having wsgi file below:
flaskapp2.wsgi
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp2/FlaskApp2")
from ashish import app as application
application.secret_key ='1233883'
The structure of file system is :
/var/www/FlaskApp2/
flskapp2.wsgi
FlaskApp2/
ashish.py
camera_pi.py
templates/index.html
The ashish.py is the flask app which is doing stream.
The error log file in apache is:
[Wed Nov 23 15:17:17.458803 2016] [mpm_prefork:notice] [pid 783] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Wed Nov 23 15:17:17.459043 2016] [core:notice] [pid 783] AH00094: Command line: '/usr/sbin/apache2'
[Wed Nov 23 15:17:14.278353 2016] [wsgi:warn] [pid 662] mod_wsgi: Compiled for Python/2.7.8.
[Wed Nov 23 15:17:14.279359 2016] [wsgi:warn] [pid 662] mod_wsgi: Runtime using Python/2.7.9.
[Wed Nov 23 15:17:14.305871 2016] [mpm_prefork:notice] [pid 662] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Wed Nov 23 15:17:14.306169 2016] [core:notice] [pid 662] AH00094: Command line: '/usr/sbin/apache2'
[Wed Nov 23 15:17:16.502484 2016] [wsgi:warn] [pid 670] mod_wsgi: Compiled for Python/2.7.8.
[Wed Nov 23 15:17:16.504897 2016] [wsgi:warn] [pid 670] mod_wsgi: Runtime using Python/2.7.9.
[Wed Nov 23 15:17:16.531217 2016] [mpm_prefork:notice] [pid 670] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Wed Nov 23 15:17:16.531502 2016] [core:notice] [pid 670] AH00094: Command line: '/usr/sbin/apache2'
On localhost it is working but not on my website is there any mistake in wsgi file or i need to add something.
You have a few possible issues when getting a 404 Not Found.
If that VirtualHost is not the only one in the Apache configuration file, then it will never be used. This is because you have set ServerName incorrectly. The ServerName directory should be set to a host name. Not a URL, not an IP address. Thus using:
ServerName https://7a78657b7a.dataplicity.io
is incorrect. It should be:
ServerName 7a78657b7a.dataplicity.io
It has to be a host name as Apache relies on it for name base virtual host matching against the Host header in the request. If it is wrong, then Apache will not know which is the correct VirtualHost to use. When this occurs Apache will fall back to sending the requests to whatever was the first VirtualHost definition it found when reading the Apache configuration files. Thus if this is not the first VirtualHost definition, it will never be used. If there is no similar URL handler set up in the first VirtualHost, you will get a 404.
The second is your WSGI application entry point in the WSGI script file pointed at by the WSGIScriptAlias directive, is not called application you will get a 404. You do appear to have it being called application, so you should be fine on this point and it shouldn't be the issue. There would have been a distinctive error message in the Apache error logs of this was the issue anyway.
The third is that the URL path you are using doesn't map to a route in the Flask application. There are actually two part to this. Because you are mounting at a sub URL in Apache, the URL path must at least start with /flask2. With that value it means you need to have a route in your Flask application which matches the root of the site. Normally in Flask that would mean you have a route for #app.route('/') but am not sure whether that still works when you have mounted your Flask application at a sub URL in Apache. You don't show your route code, so can't see what you have. You might at least try instead using /flask2/ in the URL. If your video feed isn't at the root of the Flask application but a sub URL such as set up by #app.route('/video_feed') as given in the post you link, then you should be using /flask2/video_feed as URL path. If you don't use the correct URL you will get a 404.
My whole configuration of files were right but as i was running flask applications under apache server ,apache was not able to acess pi camera because it was not having root access to pi.so,on local server it was working but not on my website when it was running on apache.
Related
Problem
I am running apache2 on my local ubuntu server. I set up a Django project using django-admin startproject site and set up my virtual host to use a WSGI Daemon process to run the Django project. This worked and the site is accessible through its IP 192.168.1.3.
When I go to /admin, it allows me to log in and see the initial backend but loads for 5 minutes then goes to a 500 error when I click anything or reload, even when trying to access the non-admin index page. This persists until I run systemctl restart apache2 and completely restart apache or wait ~10-15 minutes until it fixes itself (only to break again immediately if I access /admin pages).
Versions
Django version 4.1.5
mod-wsgi version 4.9.4
My Attempts
If I run the project with python manage.py runserver, I can access it on 192.168.1.3:8000 and fully use the /admin backend, even creating new users, etc. I then thought it was the WSGI Daemon process somehow messing it up, so I followed the linked section of this page: https://pypi.org/project/mod-wsgi#using-mod-wsgi-express-with-django and ran the site with python manage.py runmodwsgi. The site completely works on 192.168.1.3:8000 along with the /admin, and I can create new users etc., which points to it having nothing to do with the WSGI setup (as well as the non-admin pages working fine on the virtual host WSGI).
I have fully deleted and restarted the Django project, as well as setting up new virtual host .conf files with the proper WSGI information, etc.
I read about an /admin loading issue back in Django 3.0, but I am on 4.1 so that is unrelated.
I am at a complete loss at what the issue could be at this point. Why won't my /admin section work on the virtual host??
EDIT:
The issue is actually definitely the WSGI somehow. I am getting this is my apache error log:
[Sun Jan 29 09:27:12.388714 2023] [wsgi:error] [pid 67623:tid 140212873184832] (70007)The timeout specified has expired: [client 192.168.1.10:63055] mod_wsgi (pid=67623): Failed to proxy response from daemon., referer: http://192.168.1.3/admin/
[Sun Jan 29 09:27:14.427470 2023] [wsgi:error] [pid 67624:tid 140211782657600] [client 192.168.1.10:63053] Timeout when reading response headers from daemon process 'Portfolio': /var/www/Portfolio/Portfolio/wsgi.py, referer: http://192.168.1.3/admin/auth/
[Sun Jan 29 09:27:14.949762 2023] [wsgi:error] [pid 67624:tid 140211279357504] [client 192.168.1.10:63056] Timeout when reading response headers from daemon process 'Portfolio': /var/www/Portfolio/Portfolio/wsgi.py, referer: http://192.168.1.3/admin/auth/
[Sun Jan 29 09:27:16.385674 2023] [wsgi:error] [pid 67623:tid 140212856399424] [client 192.168.1.10:63100] Truncated or oversized response headers received from daemon process 'Portfolio': /var/www/Portfolio/Portfolio/wsgi.py
I still do not know what the solution is, though.
https://forum.djangoproject.com/t/django-apache-deployment-not-working-as-intended/15800
I found the solution. Somehow during the whole setup, adding WSGIApplicationGroup %{GLOBAL} to the /etc/apache2/apache2.conf file was never recommended, at least not that I noticed, but it worked and all the admin functionality works on the virtual host through WSGI Daemon.
Hope this can help someone else.
I'm currently deploying my Django app into a CentOS 7 Server (CentOS Linux release 7.8.2003) based on Django documentation here. But I encounter this problem (Error 403) stated in the error log below.
Things to take note:
Yes, I was able to run the server through a virtual environment port 8000.
The database I'm using is mysql (guide).
Does this have any relation with the access permission set for apache? As for now, I have set the permission for apache as below:
sudo chown :apache colus_cafe/
sudo chown -R :apache colus_cafe/colus_cafe/media
Python version 3.6.8 & WSGI python36-mod_wsgi.x86_64 (guide).
What have I tried: Will be updated based on given answer
remove and reinstall virtual environment.
/etc/httpd/conf.d/django.conf:
Alias /static /home/colus/colus_cafe/colus_cafe/static
<Directory /home/colus/colus_cafe/colus_cafe/static>
Require all granted
</Directory>
Alias /media /home/colus/colus_cafe/colus_cafe/media
<Directory /home/colus/colus_cafe/colus_cafe/media>
Require all granted
</Directory>
<Directory /home/colus/colus_cafe/colus_cafe>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/colus/colus_cafe/colus_cafe/wsgi.py
WSGIDaemonProcess colus_cafe_app python-home=/home/colus/colus_cafe/env python-path=/home/colus/colus_cafe
WSGIProcessGroup colus_cafe_app
/etc/httpd/logs/error_log
Current thread 0x00007fee066d6880 (most recent call first):
[Wed Jul 08 07:11:09.691137 2020] [mpm_prefork:notice] [pid 10044] AH00170: caught SIGWINCH, shutting down gracefully
[Wed Jul 08 07:11:10.768060 2020] [core:notice] [pid 10231] SELinux policy enabled; httpd running as context system_$
[Wed Jul 08 07:11:10.769024 2020] [suexec:notice] [pid 10231] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/$[Wed Jul 08 07:11:10.789925 2020] [so:warn] [pid 10231] AH01574: module wsgi_module is already loaded, skipping
[Wed Jul 08 07:11:10.793580 2020] [lbmethod_heartbeat:notice] [pid 10231] AH02282: No slotmem from mod_heartmonitor
[Wed Jul 08 07:11:10.796988 2020] [mpm_prefork:notice] [pid 10231] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/4.6.2 Pyt$[Wed Jul 08 07:11:10.797021 2020] [core:notice] [pid 10231] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Wed Jul 08 07:11:10.798024 2020] [wsgi:warn] [pid 10232] (13)Permission denied: mod_wsgi (pid=10232):
Unable to stat Python home /home/colus/colus_cafe/env.
Python interpreter may not be able to be initialized correctly.
Verify the supplied path and access permissions for whole of the path.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Based on Maarten's comment, I have found the answer for this problem.
I need to change the access permissions of apache to read and execute the django project folder by using chmod. However, this later shows another problem below.
/etc/httpd/logs/error_log
failed to map segment from shared object permission denied mysql.
Then I found out the error shows that Python (in the virtual environment) is unable to execute the packages (mysqlclient). Hence, the solution can be found here, which to change the security context of “httpd_sys_script_exec_t” which allows Apache to execute.
I hope this helps anyone who encounters this problem. And if there are any bad practices or mistakes that I have made, please do leave a comment.
Thank you and have a nice day.
I'm attempting to deploy my Pyramid Application on AWS via Elastic Beanstalk. The upload/deploy works fine but when I send a request to the application I'm met with the following error:
File "/opt/python/run/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 839, in resolve
[Sat Jul 16 21:04:40.351021 2016] [:error] [pid 10837] [remote 76.202.70.172:28102] raise DistributionNotFound(req, requirers)
[Sat Jul 16 21:04:40.351110 2016] [:error] [pid 10837] [remote 76.202.70.172:28102] pkg_resources.DistributionNotFound: The 'MyAppName' distribution was not found and is required by the application
[Sat Jul 16 21:34:47.346311 2016] [:error] [pid 10837] [remote 76.202.70.172:28102] mod_wsgi (pid=10837): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
...where "MyAppName" is the name of my application (aka the one I've developed and am attempting to use).
From what it looks like, my actual application is not installed during the app deployment. Typically, on a local machine, after developing the application you run:
pip install -e .
in order to install the actual application you are developing. I suppose my question, although it seems silly, is: How do I actually install the application I've written onto the ec2 instance during the upload/deploy process of Elastic Beanstalk? Is there something that should be included in requirements.txt to also install the application in which the requirements.txt exists? Is this done automatically? What am I missing here?
I installed mysql and wamp 2.4 in my server . I made my wamp automatically start upon startup and also disabled wampmysqld so that it will not conflict with mysql.
Then i put my wamp online .
Last month I can smoothly access my server in my LAN network.
But sometimes this week, I cannot access my server's localhost page on my LAN network. I have to open wamp again and and restart all services and its annoying . There are days that wamp will work the whole day and sometimes you need to restart all services again what seems to be the problem and how to solve this?
I open apache logfile and find this error
[Fri Mar 11 13:45:36.654882 2016] [core:notice] [pid 3200:tid 492] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.4\\bin\\httpd.exe -d C:/wamp/bin/apache/Apache2.4.4'
[Fri Mar 11 13:45:36.655882 2016] [mpm_winnt:notice] [pid 3200:tid 492] AH00418: Parent: Created child process 3568
[Fri Mar 11 13:45:37.149910 2016] [mpm_winnt:notice] [pid 3568:tid 300] AH00354: Child: Starting 150 worker threads.
Iam trying to install and configure apache for python 2.7 to develop a django application.
wsgi module is configured.
and I had did the following settings
edit httpd config file
Alias /media/ 'D:/myProjects/mysite/site_media/'
Order deny,allow
Allow from all
WSGIScriptAlias / 'D:\myProjects\mysite\apache\django.wsgi'
Order deny,allow
Allow from all
Create a folder apache in my site,say D:\myProjects\mysite\apache
Create wsgi script named 'django.wsgi'
import os
import sys
sys.path.append('D:\myProjects')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Create a new folder in my site folder named 'site_media'
Copy all images,css,javascript here
Edit template with path to css & images like this
href="/media/style.css"
But when Enter 'http://127.0.0.1' in browser the browser is loading.....but not connecting to my site
when checked in error log
the error is
[Tue May 08 16:59:41 2012] [notice] Parent: child process exited with status 1 -- Restarting.
[Tue May 08 16:59:41 2012] [warn] mod_wsgi: Compiled for Python/2.7.
[Tue May 08 16:59:41 2012] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Tue May 08 16:59:41 2012] [notice] Apache/2.2.21 (Win32) mod_wsgi/3.3 Python/2.7.3
configured -- resuming normal operations
[Tue May 08 16:59:41 2012] [notice] Server built: Sep 9 2011 10:26:10
[Tue May 08 16:59:41 2012] [notice] Parent: Created child process 2408
[Tue May 08 16:59:41 2012] [warn] mod_wsgi: Compiled for Python/2.7.
[Tue May 08 16:59:41 2012] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Tue May 08 16:59:41 2012] [notice] Child 2408: Child process is running
ImportError: No module named site
Please help me ..
if you are using apache2, you have to configure /etc/apache2/sites-enabled/000-default because it doesnt use httpd.config you have mentioned...