刷卡机刷卡显示tcp连接超时
网上关于刷卡机刷卡显示tcp连接超时的刷卡知识比较多,也有关于刷卡机刷卡显示tcp连接超时的问题,今天第一pos网(www.pos-diy.com)为大家整理刷卡常见知识,未来的我们终成一代卡神。
本文目录一览:
刷卡机刷卡显示tcp连接超时
参考 http://cn.python-requests.org/zh_CN/latest/user/advanced.html#streaming-requests
import urllib,os# opener=urllib.request.build_opener()# opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36')]# urllib.request.install_opener(opener)# for ts in pd1.url:# name = ts.split('/')[-1]# ts_url = url3.replace('index.m3u8', name)# if not os.path.exists(os.path.join('./ts', name)):# urllib.request.urlretrieve(ts_url, "ts/"+ts.split('/')[-1])headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', 'Accept': 'text/html;q=0.9,*/*;q=0.8', 'Accept-Charset': 'gbk,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding': 'gzip', 'Connection': 'close', 'Referer': None # 注意如果依然不能抓取的话,这里可以设置抓取网站的host }
为防止服务器响应缓慢,导致客服端处理异常,requests请求大多设置 timeout 参数。Requests中timeout 不设置默认值。
Timeout 类型:
连接超时指的是客户端实现到远端服务器端口的连接时request 所等待的时间。连接超时一般设为比 3 的倍数略大的一个数值,因为 TCP 数据包重传窗口的默认大小是 3。读取超时指的客户端已经连接上服务器并且发送了request后,客户端等待服务器发送请求的时间。(一般指的是服务器发送第一个字节之前的时间)。客户端timeout 秒内从基础套接字上必须接收到第一个字节的数据, 否则抛出超时异常。
# timeout 设置单一的值,将会用作 connect 和 read 二者的 timeout。requests.get('https://github.com', timeout=5)# 分别制定,就需要传入一个元组。requests.get('https://github.com', timeout=(3.05, 27))# request 永远等待,则传入一个 None 作为 timeout 的值。requests.get('https://github.com', timeout=None)
import socket# 设置超时30ssocket.setdefaulttimeout(10)try: urllib.request.urlretrieve(ts_url, ts_name)except socket.timeout: urllib.request.urlretrieve(ts_url, ts_name)
try:urllib.request.urlretrieve(ts_url, ts_name)except socket.timeout:count = 1while count <= 5:try:urllib.request.urlretrieve(ts_url, ts_name) except socket.timeout:print('timeout %d time'% count )count += 1if count > 5:raise NotImplementedError("time out")
以上就是关于刷卡机刷卡显示tcp连接超时的知识,后面我们会继续为大家整理关于刷卡机刷卡显示tcp连接超时的知识,希望能够帮助到大家!

转载请带上网址:http://www.pos-diy.com/shuaka/147116.html
- 上一篇:申请新刷卡机旧的还能用吗
- 下一篇:刷卡机服务费金额不符是怎么回事