当前位置:第一POS网 > 刷卡机知识点 >

刷卡机刷卡显示tcp连接超时

浏览:136 发布日期:2023-05-16 00:00:00 投稿人:佚名投稿

网上关于刷卡机刷卡显示tcp连接超时的刷卡知识比较多,也有关于刷卡机刷卡显示tcp连接超时的问题,今天第一pos网(www.pos-diy.com)为大家整理刷卡常见知识,未来的我们终成一代卡神。

本文目录一览:

1、刷卡机刷卡显示tcp连接超时

刷卡机刷卡显示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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 babsan@163.com 举报,一经查实,本站将立刻删除。
联系我们
订购联系:小莉
微信联系方式
地址:深圳市宝安区固戍联诚发产业园木星大厦

公司地址:深圳市宝安区固戍联诚发产业园木星大厦

举报投诉 免责申明 版权申明 广告服务 投稿须知 技术支持:第一POS网 Copyright@2008-2030 深圳市慧联实业有限公司 备案号:粤ICP备18141915号