Python 请求库 - 奇怪的行为与卷曲

Python requests library - Strange behavior vs curl

我正在比较这两个代码片段:

subprocess.call('curl -XGET http://localhost:81/proxy/bparc/my_key > /dev/null' ,shell=True)

response = requests.get('http://localhost:81/proxy/bparc/my_key')
print len(response.text)

第一个总是 运行 在 0.01 秒内。但第二个有时会花费 30 秒,而其他时间则不到 .01 秒。

知道会发生什么吗? requests 是否在做一些让事情变慢的奇特事情? 运行len不好吗?

好的,更改为 response.content 修复了它。 response.text 做了很多二进制数据不需要的额外内容。

response = requests.get('http://localhost:81/proxy/bparc/my_key')
print len(response.content)