パスワードで保護されたディレクトリを開いて読み取るPythonのurllib2の機能について読んでいますが、ドキュメントやここStackOverflowの例を見た後でも、スクリプトを機能させることができません。
import urllib2
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm=None,
uri='https://webfiles.duke.edu/',
user='someUserName',
passwd='thisIsntMyRealPassword')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
socks = urllib2.urlopen('https://webfiles.duke.edu/?path=/afs/acpub/users/a')
print socks.read()
socks.close()
コンテンツを印刷すると、開こうとしているURLがリダイレクトするログイン画面のコンテンツが印刷されます。なぜこれなのか誰もが知っていますか?