python等效于javascript的responseType =“ arraybuffer”;

时间:2019-10-15 23:34:42

标签: python python-requests http-headers

我正在使用pythons请求库发出一个返回数组缓冲区的get请求。

当我使用requests.get(url)时,最终得到的文本响应与我要查找的arraybuffer响应非常不同。

我能够以此在node / js中获得arraybuffer响应

req.onload = function(event) {
    var res = req.response;
    console.log(res)
}
req.open("GET", url, true);
req.responseType = "arraybuffer";
res = req.send() 

但是,如果排除了req.responseType = "arraybuffer",我将得到错误的文本响应,类似于python

在python请求(或另一个python http库)中,这相当于req.responseType = "arraybuffer"是什么?

感谢一堆

1 个答案:

答案 0 :(得分:0)

import requests
r = requests.get(url)
retArray = [int(i) for i in r.content]

# It seems that variable retArray is much like the arraybuffer in the browser.
# you can try it out.