Discuss / Python / 项目第七天,运行wsgiapp.py出错

项目第七天,运行wsgiapp.py出错

中原胡侃

#1 Created at ... [Delete] [Delete and Lock User]

500 Internal Server Error

Traceback (most recent call last): File "D:\Python\code\first-python-webapp\day07\src\www\transwarp\web.py", line 1499, in wsgi r = fnexec() File "D:\Python\code\first-python-webapp\day07\src\www\transwarp\web.py", line 1475, in fnroute return fn() File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\web.py", line 547, in __call return self.func(args) File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\web.py", line 1279, in _wrapper r = func(args, *kw) File "D:\Python\code\first-python-webapp\day_07\src\www\urls.py", line 15, in test_users users = User.find_all() File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\orm.py", line 250, in find_all L = db.select("select from %s" % cls.__table) File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\db.py", line 207, in _wrapper return func(args, **kw) File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\db.py", line 413, in select return _select(sql, False, args) File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\db.py", line 323, in _select cursor = _db_ctx.connection.cursor() File "D:\Python\code\first-python-webapp\day_07\src\www\transwarp\db.py", line 89, in cursor connection = engine.connect() AttributeError: 'NoneType' object has no attribute 'connect'

中原胡侃

#2 Created at ... [Delete] [Delete and Lock User]

为何engine会是None

# init db:
db.create_engine(**configs.db)

wsgiapp.py开始就已经创建engine了,为何进入main运行:

'''
A WSGI application entry.
'''

import logging; logging.basicConfig(level=logging.INFO)

import os

from transwarp import db
from transwarp.web import WSGIApplication, Jinja2TemplateEngine

from config import configs


# init db:
db.create_engine(**configs.db)

# init wsgi app:
wsgi = WSGIApplication(os.path.dirname(os.path.abspath(__file__)))

template_engine = Jinja2TemplateEngine(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'))

wsgi.template_engine = template_engine

import urls

wsgi.add_module(urls)

if __name__ == '__main__':
    wsgi.run(9000)

出现 line 89, in cursor connection = engine.connect() AttributeError: 'NoneType' object has no attribute 'connect'

Ph0eN_X

#4 Created at ... [Delete] [Delete and Lock User]

你解决了吗?我也是这个bug搞了很久,,,,

Ph0eN_X

#5 Created at ... [Delete] [Delete and Lock User]

启动的时候engine是生成了的 Init mysql engine <0x28a8270> ok. 访问http://127.0.0.1:9000/时 A server error occurred. Please contact the administrator. logging里发现engine id 变成了<0x1e23f404> 'NoneType' object has no attribute 'connect'


  • 1

Reply