_mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host

nepaul xs.nepaul at gmail.com
Wed Aug 15 21:52:29 EDT 2012


在 2012年8月16日星期四UTC+8上午12时58分07秒,Dennis Lee Bieber写道:
> On Wed, 15 Aug 2012 17:22:49 +0200, Alain Ketterlin
> 
> <alain at dpt-info.u-strasbg.fr> declaimed the following in
> 
> gmane.comp.python.general:
> 
> 
> 
> > Hans Mulder <hansmu at xs4all.nl> writes:
> 
> > 
> 
Right!
> > > On 15/08/12 15:30:26, nepaul wrote:
> 
> > >> The code:
> 
> > >> import MySQLDB
> 
> > >> strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'"
> 
> > >> 
> 
> > >> 
> 
> > >> 
> 
> > >> _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root',
> 
> > >> passwd = '123456', db = 'test', host = 'localhost'' (11004)")
> 
> > >
> 
> > > This message means that the MySQL connector cannot find 'localhost'.
> 
> > 
> 
> > No, it means that connect received a single string "user = 'root'..."
> 
> > instead of a set of individual keyword parameters, and took the whole
> 
> > string to be the name of the host (its first parameter). Of course,
> 
> > there is no host with such a name.
> 
> > 
> 
> > The solution is to parse the string into individual values, and pass
> 
> > these in the correct order.
> 
> 
> 
> 	MySQLdb code itself recommends to always use keyword parameters, so
> 
> the order shouldn't be significant... (and when one sees the list of
> 
> optional keywords, using null commas to space positional arguments would
> 
> be insane)
> 
> 
> 
> 	Parsing that string into separate fields (preferably a dictionary so
> 
> **conectitems could be used) OTOH is critical.
> 
> 
> 
> -- 
> 
> 	Wulfraed                 Dennis Lee Bieber         AF6VN
> 
>         wlfraed at ix.netcom.com    HTTP://wlfraed.home.netcom.com/




More information about the Python-list mailing list