我需要制作一个 python 应用程序来与 API 建立连接
python 应用程序会将用户的 ID 发送到 API,然后它会获取有关此用户的一些信息,例如他们的姓名、他们是否经过身份验证等。
我已经知道如何创建其余的 api,但我不知道如何使用它。
谢谢。
您可以使用请求。像这样使用它:
# 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句