Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62044 > unrolled thread

Re: Python, mySQL and password

Started byPeter Otten <__peter__@web.de>
First post2013-12-16 12:38 +0100
Last post2013-12-16 12:38 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python, mySQL and password Peter Otten <__peter__@web.de> - 2013-12-16 12:38 +0100

#62044 — Re: Python, mySQL and password

FromPeter Otten <__peter__@web.de>
Date2013-12-16 12:38 +0100
SubjectRe: Python, mySQL and password
Message-ID<mailman.4202.1387193884.18130.python-list@python.org>
Ervin Hegedüs wrote:

> Hello,
> 
> On Mon, Dec 16, 2013 at 02:55:29AM -0800, Igor Korot wrote:
>> Hi, ALL,
>> Is there a way to make python script that connects to mySQL DB ask for
>> a password on the:
>> 
>> conn = mdb.connect(host, user)
>> 
>> line.
>> The host variable is "localhost" and the user variable is "root" (for
>> developmental purposes).
> 
> may be you think some like this:
> 
> import MySQLdb
> 
> 
> dsn = {
>     'host':   "127.0.0.1",
>     'user':   "root",
>     'passwd': "",
>     'port':   3306,
>     'db':     "test"
> }
> 
> dsn['passwd'] = raw_input("Enter password for %s: " % (dsn['user']))
> 
> mysql = MySQLdb.connect(**dsn)
> cursor = mysql.cursor(MySQLdb.cursors.DictCursor)
> 
> 
> but at this way the password what you type will showing!

To avoid that use getpass.getpass() instead of raw_input().

http://docs.python.org/2/library/getpass.html

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web