Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'subject:password': 0.05; 'subject:Python': 0.06; 'cursor': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '"test"': 0.16; "'host':": 0.16; 'igor': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'all,': 0.19; 'connects': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'mon,': 0.24; 'script': 0.25; 'this:': 0.26; '(for': 0.26; 'header:X-Complaints- To:1': 0.27; 'host': 0.29; 'dec': 0.30; '"",': 0.31; 'url:python': 0.33; 'but': 0.35; 'there': 0.35; 'hi,': 0.36; 'url:org': 0.36; 'skip:m 40': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Python, mySQL and password Date: Mon, 16 Dec 2013 12:38:33 +0100 Organization: None References: <20131216111640.GA4852@arxnet.hu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p5084b396.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387193884 news.xs4all.nl 2852 [2001:888:2000:d::a6]:52586 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62044 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