用twistd部署的Flask:无法加载应用程序:'NoneType'对象没有属性'startswith' [英] Flask deployed with twistd: Failed to load application: 'NoneType' object has no attribute 'startswith'
问题描述
我试图使用.tac文件部署我的Twisted应用程序, a>
我试着用命令行来部署它:
twistd - y service.tac
我有错误:
...
application = getApplication(self.config,passphrase)
---<这里捕获的异常> ---
文件/usr/local/lib/python2.7/dist-packages/twisted/application/app.py,行450,在getApplication
application = service.loadApplication(filename,样式,密码)
文件/usr/local/lib/python2.7/dist-packages/twisted/application/service.py,第411行,在loadApplication
密码短语中)
文件/usr/local/lib/python2.7/dist-packages/twisted/persisted/sob.py,第224行,在loadValueFromFile
eval(codeObj,d,d)
文件service。 tac,第54行,在< module>中
文件/usr/lib/python2.7/ posixpath.py第61行,在isabs
返回s.startswith('/')
exceptions.AttributeError:'NoneType'对象没有属性'startswith'
加载应用程序失败:'NoneType '对象没有任何属性'startswith'
我的service.tac文件是:
<从烧瓶导入烧瓶
app =烧瓶(__ name_ _)
您的应用程序import_name无法在* .tac文件中正确标识。如果您在* .py文件中创建了应用程序并将其导入到* .tac中,那么它将工作得很好。
但是,您还需要另一个说明通过twistd部署Flask应用程序。最简单的例子如下所示:
from twisted.application import internet,service
from twisted.web.server import Site
from twisted.web.wsgi从twisted.internet导入反应器导入WSGIResource
导入反应器
$ b $ from my_flask_module import my_flask_app
application = service.Application('myapplication ')
service = service.IServiceCollection(application)
flask_resource = WSGIResource(reactor,reactor.getThreadPool(),my_flask_app)
flask_site = Site(flask_resource)
internet.TCPServer(8000,flask_site).setServiceParent(service)
I am trying to deploy my Twisted application using .tac files and twistd
I tried to deploy it with the command line:
twistd -y service.tac
I have the error:
...
application = getApplication(self.config, passphrase)
--- <exception caught here> ---
File "/usr/local/lib/python2.7/dist-packages/twisted/application/app.py", line 450, in getApplication
application = service.loadApplication(filename, style, passphrase)
File "/usr/local/lib/python2.7/dist-packages/twisted/application/service.py", line 411, in loadApplication
passphrase)
File "/usr/local/lib/python2.7/dist-packages/twisted/persisted/sob.py", line 224, in loadValueFromFile
eval(codeObj, d, d)
File "service.tac", line 54, in <module>
File "/usr/lib/python2.7/posixpath.py", line 61, in isabs
return s.startswith('/')
exceptions.AttributeError: 'NoneType' object has no attribute 'startswith'
Failed to load application: 'NoneType' object has no attribute 'startswith'
My service.tac file is:
from flask import Flask
app = Flask(__name__)
Your application import_name can't be identified properly in *.tac file. If you create flask application in *.py file and import it in *.tac it will work just fine.
But you also need another list of instructions for deploying Flask application via twistd. Minimal example looks like this:
from twisted.application import internet, service
from twisted.web.server import Site
from twisted.web.wsgi import WSGIResource
from twisted.internet import reactor
from my_flask_module import my_flask_app
application = service.Application('myapplication')
service = service.IServiceCollection(application)
flask_resource = WSGIResource(reactor, reactor.getThreadPool(), my_flask_app)
flask_site = Site(flask_resource)
internet.TCPServer(8000, flask_site).setServiceParent(service)
这篇关于用twistd部署的Flask:无法加载应用程序:'NoneType'对象没有属性'startswith'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!