嗨,我假设您通过声明REST Consumption来使用restapi作为客户机(执行GET请求或PUSH)
这可能是我个人的偏好,但我总是使用requests库来执行我的http调用
收到响应后,根据结果的类型,我将使用内置的json library或beautifulsoup解析它
使用一个返回JSON结果的restapi非常棒,因为JSON可以很容易地解码(加载)到python字典中。(python字典的结构与json-sort-of相同)
我将给您一个带有JSON响应的GET请求的示例,因为它更简单,但是您也可以很容易地找到POST请求的示例import requests
import json
dest = 'https://github.com/timeline.json'
## make the get request and store response
res = requests.get(dest)
## you might want to check if respond code is correct by accessing attribute status_code
## Get the body of the respond as text
body = res.text
## load json string ( text ) into dictionary
res_dict = json.loads(body)
## json is now a dict
assert 'messages' in res_dict
assert 'documentation_url' in res_dict