如何使用Python而不是Curl将此API请求处理为Positionly?

时间:2017-04-06 09:02:40

标签: python python-2.7 api curl pycurl

位置的API资源在这里

我有兴趣学习如何将Curl重写为Python请求,或使用 PyCurl 之类的东西来简化操作。

这是卷曲代码(我相信,如果我错了,请纠正我):

curl -X POST -d
'grant_type=password&username=USER_EMAIL&password=YOUR_PASSWORD&client_id=de3be2752e8ae27a11cd96a6b0999b0f&client_secret=8d87664221c09681c3d3bc283a50bf73'
'https://auth.positionly.com/oauth2/token'

如何使用 Python请求或PyCurl 重写?

注意:应该打印响应,并可能稍后保存到文件或类似文件中。它不能很好地验证或处理请求,然后不知道响应是什么!

我正在使用Python 2.7。

1 个答案:

答案 0 :(得分:2)

使用请求:

import requests
r = requests.post('https://auth.positionly.com/oauth2/token', data = {'grant_type':'password', 'username':'USER_EMAIL', 'password':'YOUR_PASSWORD', 'client_id':'de3be2752e8ae27a11cd96a6b0999b0f', 'client_secret':'8d87664221c09681c3d3bc283a50bf73'})
print(r.text)