Python论坛  - 讨论区

标题:Re: [python-chinese] ÔõôµÃµ½httplib µÄÒì³£ÄØ£¿

2005年02月21日 星期一 13:24

ding jianting dfar2008 at gmail.com
Mon Feb 21 13:24:55 HKT 2005

import httplib

try:
	conn = httplib.HTTPConnection("127.0.0.1:8080")
	conn.request("GET", "/")
	response = conn.getresponse()
	result = response.read()
	print result
	conn.close()
except httplib.HTTPException,msg:
	print msg
经测试以上代码可以运行。


On Mon, 21 Feb 2005 12:5:36 +0800, cry <zyqmail at 163.net> wrote:
> python,您好!
> 
> 我做了如下的代码:
> try:
>        conn = httplib.HTTPConnection("192.168.1.103")
>        conn.request("GET", "/")
>        response = conn.getresponse()
>        result = response.read()
>        conn.close()
> except httplib.HTTPException , msg:
>        print msg
> 
> 运行后:
> Traceback (most recent call last):
>  File "", line 3, in ?
>  File "I:\Python23\lib\httplib.py", line 718, in request
>    self._send_request(method, url, body, headers)
>  File "I:\Python23\lib\httplib.py", line 739, in _send_request
>    self.endheaders()
>  File "I:\Python23\lib\httplib.py", line 712, in endheaders
>    self._send_output()
>  File "I:\Python23\lib\httplib.py", line 597, in _send_output
>    self.send(msg)
>  File "I:\Python23\lib\httplib.py", line 564, in send
>    self.connect()
>  File "I:\Python23\lib\httplib.py", line 532, in connect
>    socket.SOCK_STREAM):
> error: (10060, 'Operation timed out')
> 
> 错在那里呢?我怎么能控制httplib的exception呢?
> 我这样处理ftplib就可以。
> 
> 谢谢。
> 
>> 礼!
> 
>            cry
>            zyqmail at 163.net
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 


-- 
________________________________________
ABS DFar
email: dfar2008 at gmail.com
msn:  djt2008 at hotmail.com
addr:  China ShangHai 
-----------------------------------------------------------------------


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

2005年02月21日 星期一 13:26

cry zyqmail at 163.net
Mon Feb 21 13:26:18 HKT 2005

limodou,您好!

直接用except:当然是没有问题,但是我需要错误信息呀,比如:
except error,msg:


在 2005-02-21 12:22:00 您写道:
>捕获Exception 不要httplib.HTTPException 试试
>
>
>On Mon, 21 Feb 2005 12:5:36 +0800, cry <zyqmail at 163.net> wrote:
>> python,您好!
>> 
>> 我做了如下的代码:
>> try:
>>         conn = httplib.HTTPConnection("192.168.1.103")
>>         conn.request("GET", "/")
>>         response = conn.getresponse()
>>         result = response.read()
>>         conn.close()
>>  except httplib.HTTPException , msg:
>>         print msg
>> 
>> 运行后:
>> Traceback (most recent call last):
>>   File "", line 3, in ?
>>   File "I:\Python23\lib\httplib.py", line 718, in request
>>     self._send_request(method, url, body, headers)
>>   File "I:\Python23\lib\httplib.py", line 739, in _send_request
>>     self.endheaders()
>>   File "I:\Python23\lib\httplib.py", line 712, in endheaders
>>     self._send_output()
>>   File "I:\Python23\lib\httplib.py", line 597, in _send_output
>>     self.send(msg)
>>   File "I:\Python23\lib\httplib.py", line 564, in send
>>     self.connect()
>>   File "I:\Python23\lib\httplib.py", line 532, in connect
>>     socket.SOCK_STREAM):
>> error: (10060, 'Operation timed out')
>> 
>> 错在那里呢?我怎么能控制httplib的exception呢?
>> 我这样处理ftplib就可以。
>> 
>> 谢谢。
>> 
>>>> 礼!
>> 
>>             cry
>>             zyqmail at 163.net
>> 
>> _______________________________________________
>> python-chinese list
>> python-chinese at lists.python.cn
>> http://python.cn/mailman/listinfo/python-chinese
>> 
>
>
>-- 
>I like python! 
>My Blog: http://www.donews.net/limodou
>New Maillist: http://groups-beta.google.com/group/python-cn
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese

                    致
礼!

            cry
            zyqmail at 163.net




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

2005年02月21日 星期一 13:37

cry zyqmail at 163.net
Mon Feb 21 13:37:51 HKT 2005

ding jianting,您好!

我试了你的代码,不行,和版本有关系吗?我的是:
PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information.


在 2005-02-21 13:24:00 您写道:
>import httplib
>
>try:
>	conn = httplib.HTTPConnection("127.0.0.1:8080")
>	conn.request("GET", "/")
>	response = conn.getresponse()
>	result = response.read()
>	print result
>	conn.close()
>except httplib.HTTPException,msg:
>	print msg
>经测试以上代码可以运行。
>
>
>On Mon, 21 Feb 2005 12:5:36 +0800, cry <zyqmail at 163.net> wrote:
>> python,您好!
>> 
>> 我做了如下的代码:
>> try:
>>        conn = httplib.HTTPConnection("192.168.1.103")
>>        conn.request("GET", "/")
>>        response = conn.getresponse()
>>        result = response.read()
>>        conn.close()
>> except httplib.HTTPException , msg:
>>        print msg
>> 
>> 运行后:
>> Traceback (most recent call last):
>>  File "", line 3, in ?
>>  File "I:\Python23\lib\httplib.py", line 718, in request
>>    self._send_request(method, url, body, headers)
>>  File "I:\Python23\lib\httplib.py", line 739, in _send_request
>>    self.endheaders()
>>  File "I:\Python23\lib\httplib.py", line 712, in endheaders
>>    self._send_output()
>>  File "I:\Python23\lib\httplib.py", line 597, in _send_output
>>    self.send(msg)
>>  File "I:\Python23\lib\httplib.py", line 564, in send
>>    self.connect()
>>  File "I:\Python23\lib\httplib.py", line 532, in connect
>>    socket.SOCK_STREAM):
>> error: (10060, 'Operation timed out')
>> 
>> 错在那里呢?我怎么能控制httplib的exception呢?
>> 我这样处理ftplib就可以。
>> 
>> 谢谢。
>> 
>>>> 礼!
>> 
>>            cry
>>            zyqmail at 163.net
>> 
>> _______________________________________________
>> python-chinese list
>> python-chinese at lists.python.cn
>> http://python.cn/mailman/listinfo/python-chinese
>> 
>
>
>-- 
>________________________________________
>ABS DFar
>email: dfar2008 at gmail.com
>msn:  djt2008 at hotmail.com
>addr:  China ShangHai 
>-----------------------------------------------------------------------
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese

                    致
礼!

            cry
            zyqmail at 163.net




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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号