我正在寻找一种方法来提供一些来自必应地图的图像,而不需要共享URL(因为它包含密钥)并将其返回给客户端(不需要先保存到磁盘)。我正在使用here中的此方法
def get_stream_from_url(url):
req = requests.get(url, stream = True)
return Response(stream_with_context(req.iter_content()), content_type = req.headers['content-type'])
我在另一个方法中使用它,在这个方法中,我生成一个包含这些图像信息的列表,因此基本上我希望将sream响应作为key url
的值放入json中:
编辑: 如果我打印结果,我有这个:
<type 'list'>: [{'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>} , {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>},{'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}, {'description': ' this is an example', 'url': <Response streamed [200 OK]>}]
如果我这样做,我会得到这个错误
<Response streamed [200 OK]> is not JSON serializable
这是因为函数get_stream_from_url
返回一个响应:/我的问题是我不知道如何以另一种方式发送它?在
在HTML中,我获取数据并为每个图像分配数据,如下所示:
<img class="image1 " data-description="The description" src="">
有谁能帮我,如何编码流,以便我可以发送它作为JSON数据?在
Flask
太过分了。我创建了一个名为wsinfo
的库,可以在这里找到:https://github.com/linusg/wsinfo。在有了它,代码就简单到:
^{1}$代码同时运行python2和python3,并生成一个名为
out.html
的HTML文件,其中嵌入了图像。在无需隐藏必应地图密钥。任何人都可以在免费使用条款下创建和使用它。因此,没有什么动机让他们偷你的钥匙。在大多数情况下,一个密钥似乎是被盗的,根本原因是传递包含该密钥的代码或在论坛帖子的代码示例中发布的密钥。密钥的用户通常不知道代码中的密钥。必应地图团队能够跟踪这些情况,并根据需要解决这些问题。也就是说它很少发生。一般来说,当有人想窃取必应地图的密钥时,他们只需使用必应地图网站上的密钥。在
相关问题 更多 >
编程相关推荐