Re: Help req: Problems with MySQLdb
for x in range(self.MAX_CRAWL_THREADS+1): self.con.append( [MySQLdb.connect(host,username,passwor,database,PORT),0]) PORT is an extra argument you might not have perhaps rodmc wrote: I have written an application that connects to a database on a remote machine which uses MySQLdb 1.2.0. The application works perfectly when connecting to the database from a remote machine, however when it attempts to connect to a database on the same machine a connection error is generated. I have attached what little info I can below. DBSERVERIP = 1.2.3.4 db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) --- it refuses to connect on the above line and the exception is caught and a message displayed. I have tried changing the server IP to localhost or the hostname, however the same problem arises. Information: Python 2.3.5, MySQLdb 1.2.0, MySQL 5.0.21 and Windows 2K pro. I would be grateful for any help with this problem. Kind regards, rod Also not catching exceptions is a bad idea (crash thud) for long term programs short term testing its possible it could be good. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
Simon Forman wrote: rodmc wrote: Hi, Thanks for your email. Well I am kind of new to exceptions in Python, but here is the code used below, as you can see it is somewhat basic. Is there a way to display more information about the exception? Best, rod Use the traceback module (See http://docs.python.org/lib/module-traceback.html for info on it.) import traceback try: db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) except: print A database connection error has occurred How can you assert it is a database connection error ? traceback.print_exc() return False else: pass #The rest of the program You get the same result - with a more accurate error message - by not handling the exception at all. It's generally very difficult to figure out what's going wrong without the traceback in front of you. indeed. Also, try an empty string (i.e. ) as your hostname, it's shorthand for 'localhost'. Hope this helps, ~Simon -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
Bruno Desthuilliers wrote: Simon Forman wrote: rodmc wrote: ... except: print A database connection error has occurred How can you assert it is a database connection error ? assert database connection in error (just kidding) I was really just leaving as much of the OP's code unchanged as seemed useful. Maybe they *want* to print that (possibly inaccurate) message and return False (from what appears to be module-level code at that!) FWIW, if I wanted the code to keep going but still report the exception I would use the logging module's exception() method. But that seemed a lot to explain. traceback.print_exc() return False else: pass #The rest of the program You get the same result - with a more accurate error message - by not handling the exception at all. You'd get the same traceback printed out either way, but the generic except statement with the possibly inaccurate message does seem naive to me. However, it's entirely possible that the OP *would* like the code to keep running despite any exceptions while trying to connect to the db. In that case, using traceback (or logging) is (IMHO) a reasonable way to do that but still find out what went wrong. Ciao, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Help req: Problems with MySQLdb
I have written an application that connects to a database on a remote machine which uses MySQLdb 1.2.0. The application works perfectly when connecting to the database from a remote machine, however when it attempts to connect to a database on the same machine a connection error is generated. I have attached what little info I can below. DBSERVERIP = 1.2.3.4 db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) --- it refuses to connect on the above line and the exception is caught and a message displayed. I have tried changing the server IP to localhost or the hostname, however the same problem arises. Information: Python 2.3.5, MySQLdb 1.2.0, MySQL 5.0.21 and Windows 2K pro. I would be grateful for any help with this problem. Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
Hi, Thanks for your email. Well I am kind of new to exceptions in Python, but here is the code used below, as you can see it is somewhat basic. Is there a way to display more information about the exception? Best, rod try: #Exception handler for database queries db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) except: print A database connection error has occurred return False else: #The rest of the program Sybren Stuvel wrote: rodmc enlightened us with: --- it refuses to connect on the above line and the exception is caught and a message displayed. So why do you think this exception and the error message contain no useful information at all? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
rodmc wrote: (top-post corrected) Sybren Stuvel wrote: rodmc enlightened us with: --- it refuses to connect on the above line and the exception is caught and a message displayed. So why do you think this exception and the error message contain no useful information at all? Hi, Thanks for your email. Well I am kind of new to exceptions in Python, but here is the code used below, as you can see it is somewhat basic. Is there a way to display more information about the exception? Yes : don't catch it. You'll then have all the needed infos. If you want to catch it so you can do some logging, issue a more user-friendly error message etc, then do something like this: try: SomethingThatMayRaise() except ClassOfExceptedException, e: # e is the exception, let you access error message, traceback etc doSomethingWithException(e) Some general rules about exception handling: - *don't* use bare except clause. Never. Well, almost never (cf below) - if you can't fix the problem, just let the exception propagate - at the top level of the main program, have a catch-almost-all exception handler, that will do logging if possible, proper error reporting if possible, sanity clean-up if possible, and then crash as noisily as possible. try: #Exception handler for database queries db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) except: print A database connection error has occurred return False This is the most useless and worst possible way to handle exceptions. Just get rid of this exception handler - letting the program crash with full traceback would be much much better - at least you'd have a chance to get some usefull informations about what went wrong. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
rodmc wrote: Hi, Thanks for your email. Well I am kind of new to exceptions in Python, but here is the code used below, as you can see it is somewhat basic. Is there a way to display more information about the exception? Best, rod Use the traceback module (See http://docs.python.org/lib/module-traceback.html for info on it.) import traceback try: db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) except: print A database connection error has occurred traceback.print_exc() return False else: pass #The rest of the program It's generally very difficult to figure out what's going wrong without the traceback in front of you. Also, try an empty string (i.e. ) as your hostname, it's shorthand for 'localhost'. Hope this helps, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
Do you have a MySQL acccount set up on the localhost? I usually create two users with the same privs. One for the localhost where the server is, another to connect from somewhere else. Something like mysql grant usage on *.* to 'user'@'localhost' identitfied by 'some_pass'; mysql grant usage on *.* to 'user'@'%' to identified by 'some_pass'; Check out http://dev.mysql.com/doc/refman/4.1/en/adding-users.html Hope this helps. rodmc wrote: I have written an application that connects to a database on a remote machine which uses MySQLdb 1.2.0. The application works perfectly when connecting to the database from a remote machine, however when it attempts to connect to a database on the same machine a connection error is generated. I have attached what little info I can below. DBSERVERIP = 1.2.3.4 db = MySQLdb.connect(host=DBSERVERIP, user=user, passwd=password, db=nuke) --- it refuses to connect on the above line and the exception is caught and a message displayed. -- http://mail.python.org/mailman/listinfo/python-list