[DB-SIG] PEP 249

M.-A. Lemburg mal at egenix.com
Mon Jun 27 07:51:11 EDT 2016


On 24.06.2016 16:31, Sigurd Jervelund Hansen wrote:
> Hi
> 
> I'm using the PEP249 as a reference, and I've stumbled upon some
> contradicting documentation in footnote 1.
> 
> If I attempt to connect to a database using the example I get the following
> error:
> 
>>>> connect(host=dbHost,user=dbUser,password=dbPassword,database=dbName)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line
> 81, in Connect
>     return Connection(*args, **kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py",
> line 193, in __init__
>     super(Connection, self).__init__(*args, **kwargs2)
> TypeError: 'database' is an invalid keyword argument for this function
> 
> Changing parameter database to db:
> 
>>>> connect(host=dbHost,user=dbUser,password=dbPassword,db=dbName)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line
> 81, in Connect
>     return Connection(*args, **kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py",
> line 193, in __init__
>     super(Connection, self).__init__(*args, **kwargs2)
> TypeError: 'password' is an invalid keyword argument for this function
> 
> Changing parameter password to passwd:
> 
>>>> connect(host=dbHost,user=dbUser,passwd=dbPassword,db=dbName)
> <_mysql.connection open to 'mysql-host' at 217e660>
> 
> In short: Parameter password should be passwd and database should be db.

The DB-API footnote only provides a guideline on how to name
the parameters. In this case the module author obviously
chose different spellings.

> Direct link to footnote <https://mail.google.com/>:
> https://www.python.org/dev/peps/pep-0249/#id40

"""
[1] 	

As a guideline the connection constructor parameters should be
implemented as keyword parameters for more intuitive use and follow this
order of parameters:
...
"""

> Link to stackoverflow with working example:
> http://stackoverflow.com/questions/372885/how-do-i-connect-to-a-mysql-database-in-python

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Jun 27 2016)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the DB-SIG mailing list