Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python flask:在此服务器上找不到请求的URL_Python_Apache_.htaccess_Flask - Fatal编程技术网

Python flask:在此服务器上找不到请求的URL

Python flask:在此服务器上找不到请求的URL,python,apache,.htaccess,flask,Python,Apache,.htaccess,Flask,我正在使用一个使用Apache2.4的共享托管帐户,尝试使用部署一个flask应用程序。我已将代码和fcgi脚本放在public_html文件夹中。文件夹的内容在上面的屏幕截图中: manage_apache.fcgi脚本是: #!/home/username/anaconda2/bin/python import sys,os from flup.server.fcgi import WSGIServer sys.path.insert(0, '/home/username/public_ht

我正在使用一个使用Apache2.4的共享托管帐户,尝试使用部署一个flask应用程序。我已将代码和fcgi脚本放在public_html文件夹中。文件夹的内容在上面的屏幕截图中:

manage_apache.fcgi脚本是:

#!/home/username/anaconda2/bin/python
import sys,os
from flup.server.fcgi import WSGIServer
sys.path.insert(0, '/home/username/public_html')
from myflaskapp.settings import Config, SharedConfig
from myflaskapp.app import create_app

if __name__ == '__main__':
    app = create_app(SharedConfig)
    WSGIServer(app).run()
我已经完成了最后一步,在命令行中使用putty-to-SSH进行测试时:

[~/public_html]# ./manage_apache.fcgi
我可以看到正在生成的正确网页,因此我假设我的主机支持fast cgi。我没有收到任何python错误

本文中的.htaccess文件是:

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ manage_apache.fcgi/$1 [QSA,L]
在浏览器中,当我浏览mysite.org时,我得到

Not Found

The requested URL /manage_apache.fcgi/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
根据支持,.htaccess文件正在重定向到manage_apache.fcgi/$1

-rwxr-xr-x 1 myusername myusername Nov 22 17:26 manage_apache.fcgi*

如何修复此问题?

我怀疑该主机不支持
fcgi
。主机允许您在命令行上运行Python脚本并不意味着它们已经在Apache中配置了mod_fcgi

试试这个:
apachectl-t-D DUMP|u MODULES | grep cgi
。您应该看到
fcgi_模块
fastcgi_模块
,或者可能是
cgi_模块

如果只看到
cgi\u模块
,则应该能够使用
AddHandler cgi script.py
而不是
AddHandler fcgid script.fcgi

如果您没有看到这些模块,那么您可以尝试
wsgi
apachectl-t-D DUMP|u模块| grep wsgi
。如果您看到
wsgi\u模块
,那么您就知道可以使用
wsgi
。在那一点上,我怀疑

sys.path.insert(0, '/home/username/public_html')
是绝对路径,但flask应用程序正在查找与flask网关相关的相对路径,并且找不到它

您是否尝试在应用程序实例中包装库-移动应用程序实例中的绝对路径

例如,请参见: 从werkzeug.wrappers导入请求,响应

@Request.application
def application(request):
    return Response('Hello World!')

if __name__ == '__main__':
    from werkzeug.serving import run_simple
    # move absolute path here
    run_simple('localhost', 4000, application)

谢谢你看这个。你说的“移动绝对路径”是什么意思?这是否意味着sys.path.insert(0,'/home/username/public_html')是一个取自WSGI包装器的模型,您应该修改它。尝试在模块应用程序本身中导入路径和wsgi模块。另一种选择是使用flask模板,它允许您提供“公共”静态文件夹中的文件—相对于应用程序路径的公共文件夹。这个链接展示了如何从filestystemloader:服务文件,也可以查看:并可以帮助您处理逻辑。很抱歉,我的笔记本电脑正在维护中,我不能做更多的事情了:/谢谢您的回答。我尝试了:“apachectl-t-D DUMP_MODULES”,但没有找到-bash:apachectl:command。我可以让技术支持人员帮我运行这个程序,但是有没有其他方法可以获取此信息?最好让技术支持人员确认您正在使用Apache,并告诉您是否启用了CGI或FCGI。他们说CGI或FCGI都没有启用。