Python论坛  - 讨论区

标题:[python-chinese] 疯了疯了,大人们帮忙看看

2006年11月28日 星期二 15:26

tdus lost tdus.lost在gmail.com
星期二 十一月 28 15:26:08 HKT 2006

搞了一天的python代理,看文档,搜google,换python版本,连重装系统都试了,它还是出那个异常,疯了

代码就两三行:
import urllib
someurl='http://www.google.com'
proxies={'http':'http://192.168.0.1:808'}
urllib.urlopen(someurl,proxies=proxies)

一直出这个异常:
Traceback (most recent call last):
  File "", line 1, in 
    urllib.urlopen(someurl,proxies=proxies)
  File "C:\Python25\lib\urllib.py", line 82, in urlopen
    return opener.open(url)
  File "C:\Python25\lib\urllib.py", line 190, in open
    return getattr(self, name)(url)
  File "C:\Python25\lib\urllib.py", line 334, in open_http
    return self.http_error(url, fp, errcode, errmsg, headers)
  File "C:\Python25\lib\urllib.py", line 351, in http_error
    return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "C:\Python25\lib\urllib.py", line 608, in http_error_default
    return addinfourl(fp, headers, "http:" + url)
  File "C:\Python25\lib\urllib.py", line 951, in __init__
    addbase.__init__(self, fp)
  File "C:\Python25\lib\urllib.py", line 898, in __init__
    self.read = self.fp.read
AttributeError: 'NoneType' object has no attribute 'read'

urllib2也试过了,看了一个英文网页说urllib2不用设置代理,它会自动侦测代理,但是还是没用,出另外一个异常,按说我重装过系统了,应该不是系统问题了,那到底是什么问题?还求各位大人赐教啊啊啊啊

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 04:01

Young fivesheep在gmail.com
星期三 十一月 29 04:01:25 HKT 2006

urllib2例子 :

import urllib2
proxy_handler=urllib2.ProxyHandler({"http":"http://127.0.0.1:8118/"})
opener=urllib2.build_opener(proxy_handler)  # 如果要让连接支持cookie之类的功能, 请查看此方法的相关文档
req=urllib2.Request("http://www.google.com",None,{'User-agent':
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)'})
resp=opener.open(req)
print resp.read()


On 11/28/06, tdus lost <tdus.lost在gmail.com> wrote:
> 搞了一天的python代理,看文档,搜google,换python版本,连重装系统都试了,它还是出那个异常,疯了
>
> 代码就两三行:
> import urllib
> someurl='http://www.google.com'
> proxies={'http':'http://192.168.0.1:808'}
> urllib.urlopen(someurl,proxies=proxies)
>
> 一直出这个异常:
> Traceback (most recent call last):
>   File "", line 1, in 
>     urllib.urlopen(someurl,proxies=proxies)
>   File "C:\Python25\lib\urllib.py", line 82, in urlopen
>     return opener.open(url)
>   File "C:\Python25\lib\urllib.py", line 190, in open
>     return getattr(self, name)(url)
>   File "C:\Python25\lib\urllib.py", line 334, in open_http
>     return self.http_error(url, fp, errcode, errmsg, headers)
>   File "C:\Python25\lib\urllib.py", line 351, in http_error
>     return self.http_error_default(url, fp, errcode, errmsg, headers)
>   File "C:\Python25\lib\urllib.py", line 608, in http_error_default
>     return addinfourl(fp, headers, "http:" + url)
>   File "C:\Python25\lib\urllib.py", line 951, in __init__
>     addbase.__init__(self, fp)
>   File "C:\Python25\lib\urllib.py", line 898, in __init__
>     self.read = self.fp.read
> AttributeError: 'NoneType' object has no attribute 'read'
>
> urllib2也试过了,看了一个英文网页说urllib2不用设置代理,它会自动侦测代理,但是还是没用,出另外一个异常,按说我重装过系统了,应该不是系统问题了,那到底是什么问题?还求各位大人赐教啊啊啊啊
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 08:41

boyeestudio boyee118在gmail.com
星期三 十一月 29 08:41:54 HKT 2006

2006/11/29, Young <fivesheep在gmail.com>:
>
> urllib2Àý×Ó :
>
> import urllib2
> proxy_handler=urllib2.ProxyHandler({"http":"http://127.0.0.1:8118/"})
> opener=urllib2.build_opener(proxy_handler)  # Èç¹ûÒªÈÃÁ¬½ÓÖ§³ÖcookieÖ®ÀàµÄ¹¦ÄÜ,
> Çë²é¿´´Ë·½·¨µÄÏà¹ØÎĵµ
> req=urllib2.Request("http://www.google.com",None,{'User-agent':
> 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)'})
> resp=opener.open(req)
> print resp.read()



ÎÒÓÃÄãÕâ¸ö·½·¨£¬³öÏÖÏÂÃæµÄÎÊÌ⣺
>>> import urllib2
>>> proxy_handler=urllib2.ProxyHandler({"http":"http://proxyxx.boyee.com.cn
"})
>>> opener=urllib2.build_opener(proxy_handler)
>>> req=urllib2.Request("http://www.google.com",None,{'User-agent':'Mozilla/4.0(compatible;MSIE6.0;Windows
NT 5.2)'})
>>> resq=opener.open(req)
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/urllib2.py", line 364, in open
    response = meth(req, response)
  File "/usr/lib/python2.4/urllib2.py", line 471, in http_response
    response = self.parent.error(
  File "/usr/lib/python2.4/urllib2.py", line 402, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 502: Bad Gateway
×îºóÒ»²½»¹Ã»ÓÐÖ´ÐУ¬³öÏÖBad Gateway¡£
urllib2Öл¹ÐèÒªÉèÖÃÍø¹Ø£¿


On 11/28/06, tdus lost <tdus.lost在gmail.com> wrote:
> > ¸ãÁËÒ»ÌìµÄpython´úÀí£¬¿´Îĵµ£¬ËÑgoogle£¬»»python°æ±¾£¬Á¬ÖØװϵͳ¶¼ÊÔÁË£¬Ëü»¹ÊdzöÄǸöÒì³££¬·èÁË
> >
> > ´úÂë¾ÍÁ½ÈýÐУº
> > import urllib
> > someurl='http://www.google.com'
> > proxies={'http':'http://192.168.0.1:808'}
> > urllib.urlopen(someurl,proxies=proxies)
> >
> > Ò»Ö±³öÕâ¸öÒì³££º
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >     urllib.urlopen(someurl,proxies=proxies)
> >   File "C:\Python25\lib\urllib.py", line 82, in urlopen
> >     return opener.open(url)
> >   File "C:\Python25\lib\urllib.py", line 190, in open
> >     return getattr(self, name)(url)
> >   File "C:\Python25\lib\urllib.py", line 334, in open_http
> >     return self.http_error(url, fp, errcode, errmsg, headers)
> >   File "C:\Python25\lib\urllib.py", line 351, in http_error
> >     return self.http_error_default(url, fp, errcode, errmsg, headers)
> >   File "C:\Python25\lib\urllib.py", line 608, in http_error_default
> >     return addinfourl(fp, headers, "http:" + url)
> >   File "C:\Python25\lib\urllib.py", line 951, in __init__
> >     addbase.__init__(self, fp)
> >   File "C:\Python25\lib\urllib.py", line 898, in __init__
> >     self.read = self.fp.read
> > AttributeError: 'NoneType' object has no attribute 'read'
> >
> >
> urllib2Ò²ÊÔ¹ýÁË£¬¿´ÁËÒ»¸öÓ¢ÎÄÍøҳ˵urllib2²»ÓÃÉèÖôúÀí£¬Ëü»á×Ô¶¯Õì²â´úÀí£¬µ«ÊÇ»¹ÊÇûÓ㬳öÁíÍâÒ»¸öÒì³££¬°´ËµÎÒÖØ×°¹ýϵͳÁË£¬Ó¦¸Ã²»ÊÇϵͳÎÊÌâÁË£¬Äǵ½µ×ÊÇʲôÎÊÌ⣿»¹Çó¸÷λ´óÈ˴ͽ̰¡°¡°¡°¡
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/224d2791/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 10:06

wang bin wangbin1979在gmail.com
星期三 十一月 29 10:06:15 HKT 2006

> 我用你这个方法,出现下面的问题:
> >>> import urllib2
> >>>
> proxy_handler=urllib2.ProxyHandler({"http":"http://proxyxx.boyee.com.cn"})
> >>> opener= urllib2.build_opener(proxy_handler)
> >>>
> req=urllib2.Request("http://www.google.com",None,{'User-agent':'Mozilla/4.0(compatible;MSIE6.0;Windows
> NT 5.2)'})
> >>> resq= opener.open(req)
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.4/urllib2.py", line 364, in open
>     response = meth(req, response)
>   File "/usr/lib/python2.4/urllib2.py", line 471, in
> http_response
>     response = self.parent.error(
>   File "/usr/lib/python2.4/urllib2.py", line 402, in error
>     return self._call_chain(*args)
>   File "/usr/lib/python2.4/urllib2.py", line 337, in
> _call_chain
>     result = func(*args)
>   File "/usr/lib/python2.4/urllib2.py", line 480, in
> http_error_default
>     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> urllib2.HTTPError: HTTP Error 502: Bad Gateway
> 最后一步还没有执行,出现Bad Gateway。
> urllib2中还需要设置网关?
>

应该是代理出问题了吧?

-- 
想飞之心,永远不死!
Registered Linux User 404987 [http://counter.li.org]

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月30日 星期四 01:10

Young fivesheep在gmail.com
星期四 十一月 30 01:10:40 HKT 2006

On 11/29/06, wang bin <wangbin1979在gmail.com> wrote:
> > 我用你这个方法,出现下面的问题:
> > >>> import urllib2
> > >>>
> > proxy_handler=urllib2.ProxyHandler({"http":"http://proxyxx.boyee.com.cn"})
> > >>> opener= urllib2.build_opener(proxy_handler)
> > >>>
> > req=urllib2.Request("http://www.google.com",None,{'User-agent':'Mozilla/4.0(compatible;MSIE6.0;Windows
> > NT 5.2)'})
> > >>> resq= opener.open(req)
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> >   File "/usr/lib/python2.4/urllib2.py", line 364, in open
> >     response = meth(req, response)
> >   File "/usr/lib/python2.4/urllib2.py", line 471, in
> > http_response
> >     response = self.parent.error(
> >   File "/usr/lib/python2.4/urllib2.py", line 402, in error
> >     return self._call_chain(*args)
> >   File "/usr/lib/python2.4/urllib2.py", line 337, in
> > _call_chain
> >     result = func(*args)
> >   File "/usr/lib/python2.4/urllib2.py", line 480, in
> > http_error_default
> >     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> > urllib2.HTTPError: HTTP Error 502: Bad Gateway
> > 最后一步还没有执行,出现Bad Gateway。
> > urllib2中还需要设置网关?
> >
>
> 应该是代理出问题了吧?
>
> --
> 想飞之心,永远不死!
> Registered Linux User 404987 [http://counter.li.org]
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号