Skip to content

Instantly share code, notes, and snippets.

@eight
Created November 6, 2009 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eight/227549 to your computer and use it in GitHub Desktop.
Save eight/227549 to your computer and use it in GitHub Desktop.
#!/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