Python论坛  - 讨论区

标题:[python-chinese] urlopen不行?

2006年11月27日 星期一 10:44

tdus lost tdus.lost在gmail.com
星期一 十一月 27 10:44:18 HKT 2006

不好意思用这个名字吸引眼球.

问题是这样的:我现在的网络环境必须通过代理上网,但是用urllib模块的urlopen方法无效,请问如何解决?

我的用法是:
import urllib
proxies={'http':'http://192.168.0.1:808'}
sock=urllib.urlopen('http://www.sina.com.cn',proxies=proxies)
html=sock.read()
sock.close()
print html

返回以下错误:

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

2006年11月27日 星期一 10:47

xxmplus xxmplus在gmail.com
星期一 十一月 27 10:47:13 HKT 2006

  • Missing or unknown request method
  • Missing URL
  • Missing HTTP Identifier (HTTP/1.0)
  • Request is too large
  • Content-Length missing for POST or PUT requests
  • Illegal character in hostname; underscores are not allowed http的header看上去不对阿 On 11/27/06, tdus lost <tdus.lost at gmail.com> wrote: > 不好意思用这个名字吸引眼球. > > 问题是这样的:我现在的网络环境必须通过代理上网,但是用urllib模块的urlopen方法无效,请问如何解决? > > 我的用法是: > import urllib > proxies={'http':'http://192.168.0.1:808'} > sock=urllib.urlopen('http://www.sina.com.cn',proxies=proxies) > html=sock.read() > sock.close() > print html > > 返回以下错误: > > "http://www.w3.org/TR/html4/loose.dtd"> > > ERROR: The requested URL could not be retrieved > > >

    ERROR

    >

    The requested URL could not be retrieved

    >
    >

    > While trying to process the request: >

    > GET  HTTP/1.0
    > Host: www.sina.com.cn
    > User-Agent: Python-urllib/1.17
    >
    >
    > 
    >

    > The following error was encountered: >

      >
    • > > Invalid Request > >
    > >

    > Some aspect of the HTTP Request is invalid. Possible problems: >

      >
    • Missing or unknown request method >
    • Missing URL >
    • Missing HTTP Identifier (HTTP/1.0) >
    • Request is too large >
    • Content-Length missing for POST or PUT requests >
    • Illegal character in hostname; underscores are not allowed >
    >

    Your cache administrator is webmaster. > >
    >


    >
    > Generated Mon, 27 Nov 2006 02:42:08 GMT by xa66-64.sina.com.cn > (CachePower/1.3.1.dev) >
    > > > > 而我能在邮件列表上发帖就证明我的代理是没问题的,还请高手们帮忙看看. > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- Any complex technology which doesn't come with documentation must be the best available.

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

    2006年11月27日 星期一 13:06

    boyeestudio boyee118在gmail.com
    星期一 十一月 27 13:06:29 HKT 2006

    2006/11/27, tdus lost <tdus.lost在gmail.com>:
    >
    > ²»ºÃÒâ˼ÓÃÕâ¸öÃû×ÖÎüÒýÑÛÇò.
    >
    > ÎÊÌâÊÇÕâÑùµÄ:ÎÒÏÖÔÚµÄÍøÂç»·¾³±ØÐëͨ¹ý´úÀíÉÏÍø,µ«ÊÇÓÃurllibÄ£¿éµÄurlopen·½·¨ÎÞЧ,ÇëÎÊÈçºÎ½â¾ö?
    
    
    ºÃ×Å°¡£¬ÎÒÕâÀïÒ²ÒªÓôúÀí£¬ÎÒÓÃÄãÕâ¸ö·½·¨£¬¿ÉÒÔ°ÑGOOGLEµÄÊ×Ò³´ò¿ª£¡ÎÒ°ÑËüдÈëµ½Îļþ£¬´ò¿ªÊ±Ò²ºÜÕý³£°¡£¡
    
    ÎÒµÄÓ÷¨ÊÇ:
    > import urllib
    > proxies={'http':'http://192.168.0.1:808'}
    
    
    »³ÒÉÄãÕâ¸ö¶Ë¿Úд´íÁË£¬ÊDz»ÊÇ8080µÄ¡£
    
    sock=urllib.urlopen('http://www.sina.com.cn',proxies=proxies)
    > html=sock.read()
    > sock.close()
    > print html
    >
    > ·µ»ØÒÔÏ´íÎó:
    > > "http://www.w3.org/TR/html4/loose.dtd">
    > 
    > ERROR: The requested URL could not be retrieved
    > 
    > 
    > 

    ERROR

    >

    The requested URL could not be retrieved

    >
    >

    > While trying to process the request: >

    > GET  HTTP/1.0
    > Host: www.sina.com.cn
    > User-Agent: Python-urllib/1.17
    >
    >
    > 
    >

    > The following error was encountered: >

      >
    • > > Invalid Request > >
    > >

    > Some aspect of the HTTP Request is invalid. Possible problems: >

      >
    • Missing or unknown request method >
    • Missing URL >
    • Missing HTTP Identifier (HTTP/1.0) >
    • Request is too large >
    • Content-Length missing for POST or PUT requests >
    • Illegal character in hostname; underscores are not allowed >
    >

    Your cache administrator is webmaster. > >
    >


    >
    > Generated Mon, 27 Nov 2006 02:42:08 GMT by xa66-64.sina.com.cn > (CachePower/1.3.1.dev) >
    > > > > ¶øÎÒÄÜÔÚÓʼþÁбíÉÏ·¢Ìû¾ÍÖ¤Ã÷ÎҵĴúÀíÊÇûÎÊÌâµÄ,»¹Çë¸ßÊÖÃÇ°ïæ¿´¿´. > _______________________________________________ > 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/20061127/34076380/attachment-0001.html

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

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

      你的回复:

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

      Zeuux © 2025

      京ICP备05028076号