0

我真的很难解决这个问题,也许有人可以指出我正确的方向:

我正在将 python(django 框架)用于 Web 应用程序,并且我有一个额外的 Web 套接字服务器,它从浏览器接收分块的二进制数据。我想使用 python-requests 库将这些块发送(或流式传输)到另一台服务器。

根据官方文档,您必须提供一个生成器作为数据属性:

arr = []

def streamer():
    global arr
    for i in arr:
        yield i

#lets say this function will get called when a "stream-start" message is sent to the web-socket server
def onStart():
    resp = requests.post("http://some.url/chunked", data=streamer())

#lets say this function will get called when a chunk of binary data is sent to the web-socket server
def onChunk(chunk):
    arr.append(chunk)

在这种情况下,我怎么可能发送任何东西,因为arr我发送请求时是空的。如何保持连接打开,以便发送每个块?

我认为一般来说流媒体存在一些我不理解的主要问题。因此,除了有关解决我的实际问题的提示之外,我还将感谢任何推荐的教程或有关此主题的良好阅读。

4

0 回答 0