1、stream=True时,解决连接超时或状态码为200时代码运行出错的问题
while isDuringThatTime(now_time_change, minute_30):
try:
r = requests.get(stream_url, stream=True, headers=headers, timeout=(3, 5))
connect_status = r.status_code # 返回状态码200
if connect_status == 200:
with open(stream_name, 'wb') as f:
try:
print("开始录制广播流..." + str(datetime.datetime.now()))
stream_length = r.iter_content(chunk_size=None, decode_unicode=True)
for block in stream_length:
f.write(block)
if not isDuringThatTime(now_time_change, minute_30):
print("停止录制广播流..." + str(datetime.datetime.now()))
f.close()
SendGroupMsg('FM' + datetime.datetime.now().date().isoformat() + '音频成功抓取', '','')
break
except requests.exceptions.Timeout:
print("录制出错!")
pass
else:
print('status is 403')
pass
except requests.exceptions.Timeout:
print("连接超时!")
pass
2、pyautogui点击不起作用?以“管理员身份运行”,无论是在pycharm还是powershell中运行python代码即可解决。
3、confidence=0.95,模糊匹配,解决pyautogui匹配不到的问题
# START BUTTON
btm = pyautogui.locateOnScreen(r'img\button_start.png', confidence=0.95)
while True:
if btm is None:
time.sleep(1)
btm = pyautogui.locateOnScreen(r'img\button_start.png', confidence=0.95)
print('未找到开始按钮!')
else:
break