Python Gotcha's?

Chris Angelico rosuav at gmail.com
Sun Apr 8 14:24:42 EDT 2012


On Mon, Apr 9, 2012 at 3:55 AM, Miki Tebeka <miki.tebeka at gmail.com> wrote:
>> 8.  Opening a URL can result in an unexpected prompt on
>> standard input if the URL has authentication.  This can
>> stall servers.
> Can you give an example? I don't think anything in the standard library does that.

I just threw together a quick test with a page on my local server that
returns 401 Unauth and calls for basic authentication. With Python 2:

Python 2.4.5 (#1, Jul 22 2011, 02:01:04)
[GCC 4.1.1] on mingw32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.urlopen("http://CENSORED")
Enter username for CENSORED at CENSORED:
Warning: Problem with getpass. Passwords may be echoed.
Enter password for  in CENSORED at CENSORED:
<addinfourl at 11192172 whose fp = <socket._fileobject object at 0x00ADAC34>>

I hit enter twice and that's what it did. (The "Enter password for
in" presumably would be quoting back my username.)

Using the same URL with urllib2.urlopen() threw an HTTPError exception
citing the 401.

In Python 3, urllib.request.urlopen() throws HTTPError as above.

So it seems that this gotcha, while a very real problem, is only an
issue with a deprecated module on the old branch of Python. Unless
it's somewhere else that I couldn't find?

ChrisA



More information about the Python-list mailing list