Video Straming on raspberrypi using flask apche2and wsgi server

帅比萌擦擦* 提交于 2019-12-25 04:23:05

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/40768567/video-straming-on-raspberrypi-using-flask-apche2and-wsgi-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!