似乎我时不时地收到一个不好的响应,我看到在标题content-legth:0中,但似乎我只在标题中得到了content-length,这是一个不好的响应,我不是总是得到响应的内容长度? 这是我的代码
import requests
import json
from pprint import pprint
import time
def read_OSRS_GE(item_id):
api_url="http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item="
# get all items and put em in file
# print(api_url+str(item_id))
r=requests.get(api_url+str(item_id))
print(r)
header=r.headers
print(header)
data=r.json()
# print("dataid",data["item"]["id"])
# pprint(data)
row=[]
row.append(int(time.time()))
row.append(data["item"]["id"])
row.append(data["item"]["name"])
row.append(data["item"]["current"]["price"])
row.append(data["item"]["members"])
print(row)
return
def get_items():
api_url="https://rsbuddy.com/exchange/summary.json"
#get all items and put em in file
# print(api_url)
r=requests.get(api_url)
data=r.json()
# pprint(data)
counter=1
for key, value in data.items():
print("item id:",key)
print("call:",counter)
read_OSRS_GE(key)
counter+=1
return
get_items()
答案 0 :(得分:1)
您可以从len(r.content)
响应不一定设置Content-Length
头。
您提供的示例中的响应当前包含一个Transfer-Encoding
字段。数据按一系列块发送,因此发出Content-Length
头。