【问题标题】:Python [ mod_wsgi ] works via cli but not via apachePython [ mod_wsgi ] 通过 cli 工作,但不能通过 apache
【发布时间】:2013-05-05 17:10:48
【问题描述】:

cli:

[root@localhost 0]# python test13.wsgi
(1, 'aaaaaa')
[root@localhost 0]# 

阿帕奇:

内部服务器错误

完整的脚本代码:

import MySQLdb
conn = MySQLdb.connect (host = "localhost",
                        user = "root",
                        passwd = "",
                        db = "aaa")
cursor = conn.cursor ()
cursor.execute ("select * from bbb limit 1")
row = cursor.fetchone ()
print row
cursor.close ()
conn.close ()

def application(environ, start_response):
    start_response('200 OK', [('content-type', 'text/html')])
    return row

错误日志:

[Fri May 10 16:04:07 2013] [info] mod_wsgi (pid=3692): Attach interpreter ''.
[Fri May 10 16:04:20 2013] [info] mod_wsgi (pid=3691): Create interpreter 'localhost.localdomain|/0'.
[Fri May 10 16:04:20 2013] [info] [client 127.0.0.1] mod_wsgi (pid=3691, process='', application='localhost.localdomain|/0'): Loading WSGI script '/0/test13.wsgi'.
[Fri May 10 16:04:20 2013] [error] (1, 'aaaaaa')
[Fri May 10 16:04:20 2013] [error] [client 127.0.0.1] mod_wsgi (pid=3691): Exception occurred processing WSGI script '/0/test13.wsgi'.
[Fri May 10 16:04:20 2013] [error] [client 127.0.0.1] TypeError: sequence of byte string values expected, value of type int found

【问题讨论】:

  • 你的 return 声明破坏了它。
  • 它应该在 [] 中吗?我的其他 hello world 示例有.. return [output]
  • row 中的第一个元素是整数。 return [repr(row)] 应该可以工作。
  • 那么,我怎样才能将此评论选择为“已回答”。 ?效果很好。

标签: python python-2.7 mod-wsgi wsgi mysql-python


【解决方案1】:

application 应该返回一个可迭代的字符串。你的返回一个整数和一个字符串的元组(它是一个可迭代的),这不起作用:

TypeError: sequence of byte string values expected, value of type int found

return 行更改为:

return [repr(row)]

【讨论】:

    猜你喜欢
    • 2012-10-24
    • 2016-03-30
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多