Windows 7 で python 3.3.0 を使用しています。
システム上でバイパスするようにこのスクリプトを作成しhttp proxy without authentication
ました。しかし、実行するとエラーが発生UnicodeEncodeError: 'charmap' codec can't encode characters in position 6242-6243: character maps to <undefined>
します。Unicode 文字を文字列にデコードできないようです。
では、何を使用または編集/実行する必要がありますか? 誰にも手がかりや解決策はありますか?
私.py
には以下が含まれます:
import sys, urllib
import urllib.request
url = "http://www.python.org"
proxies = {'http': 'http://199.91.174.6:3128/'}
opener = urllib.request.FancyURLopener(proxies)
try:
f = urllib.request.urlopen(url)
except urllib.error.HTTPError as e:
print ("[!] The connection could not be established.")
print ("[!] Error code: ", e.code)
sys.exit(1)
except urllib.error.URLError as e:
print ("[!] The connection could not be established.")
print ("[!] Reason: ", e.reason)
sys.exit(1)
source = f.read()
if "iso-8859-1" in str(source):
source = source.decode('iso-8859-1')
else:
source = source.decode('utf-8')
print("\n SOURCE:\n",source)