weixin_46566621 2021-08-28 19:11 采纳率: 100%
浏览 28
已结题

关于django使用request

在django项目当中,利用opencv对手势进行识别,并采用StreamingHttpResponse流式输出手势的状态,并将其放在 url = 'http://127.0.0.1:8000/finger_choose' 这个接口当中。
后续我想利用requests模块对其访问,代码如下:

import requests
from contextlib import closing
from collections import deque

url = 'http://127.0.0.1:8000/finger_choose'
res = requests.get(url, stream=True)

pts = deque(maxlen=2)
with closing(res) as r1:
    for i in r1.iter_content():
        pts.append(i)
        if pts[0] == b'1' and pts[-1] == b'2':
            print('握拳')

但是将requests模块嵌入到finger_url当中,就无法运行了,因为requests部分是一个死循环。
请问有方法进行改进吗?即我对url = 'http://127.0.0.1:8000/finger_choose'进行监测,如果是握拳,那么对前端的值进行一个修改。

def finger_url(request):
    user_pose = {}
    pts = deque(maxlen=2)
    url = 'http://127.0.0.1:8000/finger_choose'
    res = requests.get(url, stream=True)
    if request.method == 'POST':
        with closing(res) as r1:
            for i in r1.iter_content():
                pts.append(i)
                if pts[0] == b'1' and pts[-1] == b'1':
                    user_pose['pose'] = '握拳'
        return JsonResponse(user_pose)
    return render(request,'selects.html',locals())

  • 写回答

1条回答 默认 最新

  • Lonelypatients° 2021-08-28 21:04
    关注

    你是打算使用requests 库自己请求自己?,这操作把我看懵了, 你是想监听什么?,什么样的动作得到一个什么样的结果?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月10日
  • 已采纳回答 9月2日
  • 创建了问题 8月28日

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容