Python urllib2无法在备用端口(不是80)上打开localhost?错误10013 [英] Python urllib2 cannot open localhost on alternate port (not 80)? Error 10013

查看:629
本文介绍了Python urllib2无法在备用端口(不是80)上打开localhost?错误10013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 server.py

import BaseHTTPServer
import SocketServer

class TestRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        self.wfile.write("hello world at %s" % __file__)

server = BaseHTTPServer.HTTPServer(('', 10000), TestRequestHandler)
#server = SocketServer.ThreadingTCPServer(('', 8888), TestRequestHandler)
server.serve_forever()

这是我的 client.py

import urllib2
req = urllib2.Request('http://127.0.0.1:10000/')
handle = urllib2.urlopen(req)
content = handle.read()

然后我启动server.py,它工作

Then I start server.py, it works.

当我启动client.py时,我在Windows 7,Python 2.6 上收到此错误:

When I start client.py, I get this error on Windows 7, Python 2.6:

Traceback (most recent call last):
  File "D:\Dropbox\Forge\urllib-error\client.py", line 3, in <module>
    handle = urllib2.urlopen(req)
  File "C:\Python26\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python26\lib\urllib2.py", line 391, in open
    response = self._open(req, data)
  File "C:\Python26\lib\urllib2.py", line 409, in _open
    '_open', req)
  File "C:\Python26\lib\urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "C:\Python26\lib\urllib2.py", line 1161, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python26\lib\urllib2.py", line 1136, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions>

当我打开 http://127.0.0.1:10000/ 从浏览器,它的工作原理。这意味着服务器是正常的。

When I open http://127.0.0.1:10000/ from a browser, it works. It means server is fine.

当我更换 http:// 127.0.0.1:10000/ http://127.0.0.1/ http://127.0.0.1:80/ 在client.py中,一切正常(这是80端口上的另一个Web服务器 - apache)

When I replace http://127.0.0.1:10000/ with http://127.0.0.1/ or http://127.0.0.1:80/ in client.py, everything works fine (this is another web server on port 80 - apache).

我做错了什么?

UPD: / strong>当我使用这个 client2.py 时,同样的错误:

import urllib2
handle = urllib2.urlopen('http://127.0.0.1:10000/')
content = handle.read()

UPD:解决问题。这是我的防火墙禁用时,一切正常。愚蠢的,愚蠢的我感谢您阅读: - )

UPD: Problem solved. It was my firewall. When disabled, everything works. Stupid, stupid me. Thanks for reading :-)

推荐答案

本地防火墙阻止了连接。当它被禁用时,一切正常。

The local firewall prevented the connection. When it's disabled, everything works.

这篇关于Python urllib2无法在备用端口(不是80)上打开localhost?错误10013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆