python winerror 10065_无法建立新连接:[WinError 10060]

博主在Raspberry Pi(PiServer)上进行测试,每秒发送随机信号到本地web服务器并记录响应。随着并发请求增加至100个,出现`HTTPConnectionPool`连接错误,表现为WinError 10060。问题可能涉及web服务器处理能力、带宽限制或PiServer资源。尝试使用不同服务器(如Amazon EC2、笔记本电脑)重复实验,结果相同。
摘要由CSDN通过智能技术生成

我尝试在一个专用的Raspberry Pi(我称之为PiServer)中每隔一秒生成一个随机信号,从Raspberry Pi发送到本地web服务器。在

然后,PiServer将消息发送回Raspberry Pi,并在MySQL数据库中存储一个数据。在

现在我想看看增加发送包裹的次数需要多少时间。所以我运行以下代码(咖啡机.py)多次。在

这是我的密码

在咖啡机.py包含在客户机中from time import sleep

import requests

import datetime

import random

home = "A"

device = ["CoffeeModel01", "WashingMachine01", "RiceCooker01", "DryingMachine01", "MicrowaveModel01"]

while True:

num1 = random.randint(0, 1)

num2 = random.randint(0, 1)

num3 = random.randint(0, 1)

deviceNum = random.randint(0,4)

code = "%d%d%d" % (num1, num2, num3)

interval = random.uniform(2.0, 4.0)

timestamp = datetime.datetime.now()

payload = {"Device": device[deviceNum], "Code": code, "Time": format(timestamp), "Home": home}

print "Data Sended : Device = " + device[deviceNum] + ", Code = " + code

r = requests.post("http://160.18.2.109/HomeAuto.php", data=payload)

if r.status_code != 200:

raise Exception("Failed to post data to server")

print(r.text)

sleep(interval)

在家庭汽车.php包含在PiServer中并与SQL一起使用

^{pr2}$

问题是当我增加咖啡机.py最多100个(同时运行100个文件),某些连接已断开,日志显示如下raise ConnectionError(e, request=request)

requests.exceptions.ConnectionError: HTTPConnectionPool(host='160.18.2.109', port=80): Max retries exceeded with url: /HomeAuto.php (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))

我想知道这个问题是因为web服务器(PHP文件)还是带宽有限或者PiServer的资源。在

注意:我尝试过使用amazonec2作为服务器,同时也使用我的笔记本电脑和PiServer。所有人都有同样的问题。在

非常感谢。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值