【问题标题】:python equivalent to javascript's responseType = "arraybuffer";python相当于javascript的responseType = "arraybuffer";
【发布时间】:2019-10-15 23:34:42
【问题描述】:

我正在使用 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"?

非常感谢

【问题讨论】:

    标签: python python-requests http-headers


    【解决方案1】:
    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 2019-01-18
      • 2010-09-07
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多