[bigdata054] python3 urllib的timeout测试
发布时间:2020-12-14 03:17:09 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/env python3#! -*- coding:utf-8 -*-import timeimport urllib# requestimport urllib.requestdef test_request_get(): #要打开的url # url = 'http://www.sohuuuu.com' # url = 'http://www.sohu.com' url = 'http://127.0.0.1:6666/api/v1.0/ap
#!/usr/bin/env python3 #! -*- coding:utf-8 -*- import time import urllib # request import urllib.request def test_request_get(): #要打开的url # url = 'http://www.sohuuuu.com' # url = 'http://www.sohu.com' url = 'http://127.0.0.1:6666/api/v1.0/apicommubehavior' #设置超时时间,打开url连接 """ 如果url是http://www.sohuuuu.com,即使超时时间是timeout=0.0001,也不会立刻返回,要等很久 如果url是http://www.sohu.com,超时时间timeout=0.0001,会立刻报错。 如果url是url = 'http://127.0.0.1:6666/api/v1.0/apicommubehavior',timeout=0.0001,立刻报错。 """ t1 = time.time() try: ret = urllib.request.urlopen(url,timeout=10) except Exception as e: print(time.time() - t1) print(e) exit(1) # #返回值是一个urllib.clinet.HTTPResponse print(type(ret)) # print(dir(ret)) for i in ret.readlines(): print(i) if __name__ == '__main__': test_request_get() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |