解决使用requests实时拉流的部分问题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值