[DB-SIG] problem with MySQLdb

Ognen Duzlevski ogd116@mail.usask.ca
Sun, 21 Apr 2002 11:35:51 -0600


This is a multi-part message in MIME format.

--Boundary_(ID_r2XHdnWtbrRHFeNi2iM8Dg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

Hello,

I have the following simple cgi script:

#!c:/Python22/python.exe
import cgitb, cgi, MySQLdb
cgitb.enable()
 
print "Content-Type: text/html"
print
print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world!"

dbs = MySQLdb.connect(db='test',host='localhost',user='ognen',passwd='blahblah')
c = db.cursor()
c.execute("SELECT * FROM ")
s = c.fetchone()
print s

The whole thing works from the command prompt (python test.py) if I remove host='localhost' part from connect() but with it it wont work. When I try to access the script through the web browser I get the correct result up to the point where MySQL.connect(...) is executed:

Operational error: 2003, "Can't connect to MySQL server on 'localhost' (10061)") 
      __doc__ = 'Exception raised for errors that are related to ...cation\n error occurred during processing, etc.' 
      __getitem__ = <bound method OperationalError.__getitem__ of <_...eptions.OperationalError instance at 0x00840040>> 
      __init__ = <bound method OperationalError.__init__ of <_mys...eptions.OperationalError instance at 0x00840040>> 
      __module__ = '_mysql_exceptions' 
      __str__ = <bound method OperationalError.__str__ of <_mysq...eptions.OperationalError instance at 0x00840040>> 
      args = (2003, "Can't connect to MySQL server on 'localhost' (10061)") 

The script accessed through the web will not work with any combination of host, user and db parameters I have tried. The user has all privileges GRANTed properly as far as I can tell on the test database. If I do c:\mysql\bin\mysql -u ognen test it works just fine.

Any help would be appreciated.

Ognen

--Boundary_(ID_r2XHdnWtbrRHFeNi2iM8Dg)
Content-type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I have the following simple cgi 
script:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>#!c:/Python22/python.exe</FONT></DIV>
<DIV><FONT face=Arial size=2>import cgitb, cgi, MySQLdb</FONT></DIV>
<DIV><FONT face=Arial size=2>cgitb.enable()<BR>&nbsp;<BR>print "Content-Type: 
text/html"<BR>print<BR>print "&lt;TITLE&gt;CGI script 
output&lt;/TITLE&gt;"<BR>print "&lt;H1&gt;This is my first CGI 
script&lt;/H1&gt;"<BR>print "Hello, world!"</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>dbs = 
MySQLdb.connect(db='test',host='localhost',user='ognen',passwd='blahblah')<BR>c 
= db.cursor()<BR>c.execute("SELECT * FROM ")<BR>s = c.fetchone()<BR>print 
s</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>The whole thing works from the command prompt 
(python test.py) if I remove host='localhost' part from connect() but with it it 
wont work. When I try to access the script through the web browser I get the 
correct result up to the point where MySQL.connect(...) is 
executed:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>Operational 
error: 2003, "Can't connect to MySQL server on 'localhost' (10061)") 
<BR></FONT><FONT size=2><TT><SMALL>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL><FONT 
size=3>&nbsp;</FONT></TT></FONT><FONT face="Times New Roman" 
size=3>__doc__&nbsp;= 'Exception raised for errors that are related to 
...cation<FONT color=#c040c0>\n</FONT> error occurred during processing, etc.' 
<BR></FONT><TT><FONT 
size=2><SMALL>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL></FONT><FONT 
size=3>&nbsp;</FONT></TT><FONT face="Times New Roman" size=3>__getitem__&nbsp;= 
&lt;bound method OperationalError.__getitem__ of 
&lt;_...eptions.OperationalError instance at 0x00840040&gt;&gt; 
<BR></FONT><TT><FONT 
size=2><SMALL>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL></FONT><FONT 
size=3>&nbsp;</FONT></TT><FONT face="Times New Roman" size=3>__init__&nbsp;= 
&lt;bound method OperationalError.__init__ of 
&lt;_mys...eptions.OperationalError instance at 0x00840040&gt;&gt; 
<BR></FONT><TT><FONT 
size=2><SMALL>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL></FONT><FONT 
size=3>&nbsp;</FONT></TT><FONT face="Times New Roman" size=3>__module__&nbsp;= 
'_mysql_exceptions' <BR></FONT><TT><FONT 
size=2><SMALL>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL></FONT><FONT 
size=3>&nbsp;</FONT></TT><FONT face="Times New Roman" size=3>__str__&nbsp;= 
&lt;bound method OperationalError.__str__ of 
&lt;_mysq...eptions.OperationalError instance at 0x00840040&gt;&gt; 
<BR></FONT><FONT size=2><TT><SMALL>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL><FONT 
size=3>&nbsp;</FONT></TT></FONT><FONT size=3><FONT 
face="Times New Roman">args&nbsp;= (2003, "Can't connect to MySQL server on 
'localhost' (10061)") </FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT size=3><FONT face=Arial 
size=2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT><FONT><FONT face=Arial><FONT size=2>The script accessed through the 
web will not work with any combination of host, user and db parameters I have 
tried. The user has all privileges GRANTed properly as far as I can tell on the 
test database. If I do c:\mysql\bin\mysql -u ognen test it works just 
fine.</FONT></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any help would be appreciated.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Ognen</FONT></DIV></BODY></HTML>

--Boundary_(ID_r2XHdnWtbrRHFeNi2iM8Dg)--