我有以下代码
import requests
import sys
import json
arg_count = 0
#check that correct number of arguments are passed to utility
for arg in sys.argv:
arg_count = arg_count + 1
assert arg_count == 4
#parse the input arguments to the utility
connectplus_group_title = sys.argv[1]
connectplus_uname = sys.argv[2]
connectplus_passwords = sys.argv[3]
#find the group id from the input group name i.e connectplus_group_title
response = requests.get("https://connectplus.geometricglobal.com/_vti_bin/beezy/v2/api.svc//Groups/Availability?title={title})", auth=(connectplus_uname, connectplus_passwords))
#assert response.status_code == response.codes.ok
group_data = json.loads(response)
group_id = group_data[connectplus_group_title]
connectplus_group_contributors = "https://connectplus.geometricglobal.com/_vti_bin/beezy/v2/api.svc//Groups/{id}/Contributors?skip={skip}&take={take}"
response = requests.get(connectplus_group_contributors,auth=(connectplus_uname, connectplus_passwords))
data = response.json()
我需要获取json
返回的URL
数据,我尝试使用json.loads(response.text)
或简单json.loads(response)
但没有运气我一直收到上述错误。
从字典中获取REST
网址的数据的正确方法是什么。
答案 0 :(得分:2)
您必须传递response.content
,回复是Response
类型,而非简单字符串(尝试type(response)
)和json.loads
需要(如错误突出显示)字符串或缓冲区。
将来电替换为:
json.loads(response.content)