0

我有一个 Python 脚本。我可以从提示中晒太阳:

python myscript.py

Python 脚本连接到 MySQL 并获取/计算一些值并打印出来。

但是当我通过 Apache 运行相同的程序时:

Via Browser request 
OR
curl "http://box.com/script/myscript.py" 

我在 Apache 日志中收到以下错误:

[Tue Jun 12 03:31:57 2012] [error] [client xx.xx.xx.xx] Exception AttributeError: "Data instance has no attribute 'cursor'" in <bound method Data.__del__ of <__main__.Data instance at 0x160f4c20>> ignored

而通过 cgitb 的日志状态:

Traceback (most recent call last):
  File "cgi-bin/myscript.py", line 114, in <module>
    Data = Data()
  File "cgi-bin/myscript.py", line 14, in __init__
    self.conn = MySQLdb.connect(host="host",user="",passwd="",db="test")
AttributeError: 'module' object has no attribute 'connect'

我的盒子里安装了多个 Python,但我想知道应该如何设置以及应该设置什么配置?最大的麻烦是我怎么能从命令行运行我的脚本呢?

该脚本只是连接到后端并从表中获取值。

4

0 回答 0