Created
November 6, 2009 00:15
-
-
Save eight/227549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Python urllib2 proxy usage sample | |
""" | |
import urllib2 | |
#今回はプロキシ設定を空にしておく | |
#proxies = {'http': 'http://www.example.com:3128/'} | |
proxies = {} | |
#プロキシハンドラーを作成して | |
handler = urllib2.ProxyHandler(proxies) | |
#プロキシハンドラーを指定してURL Openerを作成して | |
opener = urllib2.build_opener(handler) | |
#作成したURL Openerをインストールしてから | |
urllib2.install_opener(opener) | |
#普通にurlopenすると例外が発生してくれる | |
try: | |
u = urllib2.urlopen('http://www.example.com/404NotFound.html') | |
print u.read() | |
except IOError,error: | |
print error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment