简体   繁体   English

MySQL-python无法在CGI中执行

[英]MySQL-python not executing in CGI

I am working with MySQL-python package. 我正在使用MySQL-python软件包。 I am able to execute MySQL dependent scripts from command line, however doing the same through browser (Apache CGI) yields the following error: 我能够从命令行执行MySQL依赖脚本,但是通过浏览器(Apache CGI)进行相同操作会产生以下错误:

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.  
/var/www/html/temp.py in ()  
9 
10 # Establich a connection
11 db = MySQLdb.connection(host="127.0.0.1", user="root", passwd="", db="inserv")
12 
13 # Run a MySQL query from Python and get the result set  
   db undefined, MySQLdb = <module 'MySQLdb' from 
  '/usr/lib64/python2.6/site-packages
/MySQLdb/__init__.pyc'>, MySQLdb.connection = <type '_mysql.connection'>,  
host undefined,   user undefined, passwd undefined

<class '_mysql_exceptions.OperationalError'>: 
(2003, "Can't connect to MySQL server on '127.0.0.1' (13)")
  args = (2003, "Can't connect to MySQL server on '127.0.0.1' (13)")
  message = '' 

I have been stuck in this situation for past few days. 过去几天,我一直处于这种情况。 MySQL commands issued through php based sites execute appropriately and I can, also, login to MySQL from command line. 通过基于php的站点发出的MySQL命令可以正确执行,我也可以从命令行登录到MySQL。 The problem seem to be with Python CGI only. 问题似乎仅在于Python CGI。

I have also tried the same with oursql package and there seems to be a similar problem. 我也尝试过与oursql包相同,似乎也有类似的问题。 How can I address this situation? 我该如何解决这种情况?

Edit 编辑
As per @Real's answer I have edited my code to use MySQLdb.connect() but the problem still persist and traceback ends with: 按照MySQLdb.connect()的答案,我已经编辑了代码以使用MySQLdb.connect()但是问题仍然存在,并且回溯以以下结尾:

2003, "Can't connect to MySQL server on '127.0.0.1' (13)"

You should be using connect, not connection. 您应该使用连接,而不是连接。 Mysqldb.connect() returns a connection object but you appear to be calling mysqldb.connection(). Mysqldb.connect()返回一个连接对象,但您似乎正在调用mysqldb.connection()。 See The docs for an example of how to do it. 有关如何执行此操作的示例,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM