2012-03-06 13 views
3

私はページのHTML(この場合はhttp://www.google.com)をダウンロードしようとしていますが、エラーが戻ってきます。Python urllib.request.urlopen()はエラー10061を返しますか?

Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win 
32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import urllib 
>>> import urllib.request 
>>> html = urllib.request.urlopen("http://www.google.com") 
Traceback (most recent call last): 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 1136, in 
do_open 
    h.request(req.get_method(), req.selector, req.data, headers) 
    File "\\****.****.org\myhome\python\lib\http\client.py", line 964, in req 
uest 
    self._send_request(method, url, body, headers) 
    File "\\****.****.org\myhome\python\lib\http\client.py", line 1002, in _s 
end_request 
    self.endheaders(body) 
    File "\\****.****.org\myhome\python\lib\http\client.py", line 960, in end 
headers 
    self._send_output(message_body) 
    File "\\****.****.org\myhome\python\lib\http\client.py", line 805, in _se 
nd_output 
    self.send(msg) 
    File "\\****.****.org\myhome\python\lib\http\client.py", line 743, in sen 
d 
    self.connect() 
    File "\\****.****.org\myhome\python\lib\http\client.py", line 721, in con 
nect 
    self.timeout, self.source_address) 
    File "\\****.****.org\myhome\python\lib\socket.py", line 404, in create_c 
onnection 
    raise err 
    File "\\****.****.org\myhome\python\lib\socket.py", line 395, in create_c 
onnection 
    sock.connect(sa) 
socket.error: [Errno 10061] No connection could be made because the target machi 
ne actively refused it 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 138, in 
urlopen 
    return opener.open(url, data, timeout) 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 369, in 
open 
    response = self._open(req, data) 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 387, in 
_open 
    '_open', req) 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 347, in 
_call_chain 
    result = func(*args) 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 1156, in 
http_open 
    return self.do_open(http.client.HTTPConnection, req) 
    File "\\****.****.org\myhome\python\lib\urllib\request.py", line 1139, in 
do_open 
    raise URLError(err) 
urllib.error.URLError: <urlopen error [Errno 10061] No connection could be made 
because the target machine actively refused it> 
>>> 

私の最高の推測では、私のネットワークのファイアウォールが(ほとんど/ 80以外のすべてのポートがブロックされている)の接続をブロックしていることである。ここに私の対話プロンプトセッションです。私はなぜ、それは見ません。 Pythonはポート80で接続しませんか?誰が何が起きているのか知っていますか?

+0

を無視するurllibはを強制する方法を示しているthe this linkであります:http://stackoverflow.com/questions/5620263/using-an-http- proxy-python(したがって、重複した質問) –

+0

私はurllib2を使用しておらず、その質問は異なっていますが、両方とも同じエラーがあります。 –

答えて

3

エラーはオペレーティングシステムレベルから来ており、Pythonには関係しません。どんなプログラミング言語でも同じです。

ファイアウォールの問題を自分で解決できる場合を除き、ネットワーク管理者に問い合わせてください。 HTTPプロキシが必要な場合は、urllibを設定することができます。

+0

Windowsでのhttp_proxy環境変数が、pythonのurllibに問題を引き起こしていることを知っておくと、この問題を自分で解決できました。それを削除して問題を解決しました – cudiaco

8

urllibはあなたがプロキシを使用している場合、それはIE、またはset it when using urllibに正しいです確認してくださいTools->Internet Options->Connections->Lan Settings

の下に通常のInternet Explorerからプロキシ設定を取ります。ブラウズにプロキシを使用しない場合は、IEのプロキシ設定が空であることを確認してください。

私は一度インストールしたサードパーティのアプリがプロキシなしでFirefoxで楽しくサーフィンしていた間に、IEの設定を変更したことに気付くまで、この問題で数時間苦労しました。


別の解決策は、おそらくあなたのソリューションがここにあるIEのプロキシ設定

+0

パーフェクト、その作業:) –

関連する問題