我需要制作一个 python 应用程序来与 API 建立连接
python 应用程序会将用户的 ID 发送到 API,然后它会获取有关该用户的一些信息,例如他们的姓名、他们是否经过身份验证等。
我已经知道如何创建 rest api,但我不知道如何使用它。
谢谢。
请您参考如下方法:
您可以使用 requests .像这样使用它:
# Get
resp = requests.get('https://api.github.com/user', auth=('user', 'pass'))
json_response = resp.json()
# Response: {u'private_gists': 419, u'total_private_repos': 77, ...}
is_authenticated = json_response.get('is_authenticated', False)
if is_authenticated == True:
# Do stuff
# Post
r = requests.post('http://httpbin.org/post', data = {'key':'value'})
r.json()
# Similar response as above
