shihezichen 发表于 2014-02-07 22:44

python 的urllib的urlopen返回10038错误,是怎么回事?

代码很简单, 如下所示.信息如下:
0. windows是64bit win7, 安装的是64位的官方python( 试过32位的python, 问题现象一样)
1. 昨天晚上相同的代码还能访问, 今天再调用时, 就无法访问了.返回10038错误.   我试过了, 使用浏览器访问时可以的.
2. 相同的代码,访问其他网站, 例如www.iteye.com是可以的(当然, iteye不需要验证,因此要去掉auth部分的代码).
3. 这个错误码我google了, 发现都没有合适的解释


代码如下:
u='xxx'
        p='xxxx'
        a_url = 'http://stonyyy.xxxxx.org:100/status_probe.html'


        password_mgr= urllib2.HTTPPasswordMgrWithDefaultRealm()
        password_mgr.add_password(realm=None,uri=a_url,user=u,passwd=p)
错误信息如下:
Traceback (most recent call last):
File "status.py", line 179, in <module>
    response= urllib2.urlopen(a_url)
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 404, in open
    response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 422, in _open
    '_open', req)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error >
请按任意键继续. . .



shihezichen 发表于 2014-02-07 22:54

代码贴上来发现有问题, 重新发一下代码:

代码如下:
u='xxx'
p='xxxx'
a_url = 'http://stonyyy.xxxxx.org:100/status_probe.html'

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(realm=None,uri=a_url,user=u,passwd=p)
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.HTTPBasicAuthHandler( password_mgr )
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener( opener )

response = urllib2.urlopen(a_url)
print response.headers

bikong0411 发表于 2014-02-08 09:35

10038是socket没有打开,socke底层的错误
页: [1]
查看完整版本: python 的urllib的urlopen返回10038错误,是怎么回事?