Gou*_*un2 1 python django django-rest-framework
我需要创建一个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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
94 次 |
| 最近记录: |