如何使用 Python 而不是 Curl 来处理这个 API 对 Positionly 的请求?
How can I process this API request to Positionly using Python and not Curl?
Positionly 的 API 资源在这里:
我有兴趣学习如何将 Curl 重写为 Python 请求,或使用类似 PyCurl 的东西来让事情变得更简单。
这是 Curl 代码(我相信,如果我错了请纠正我):
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.
使用请求:
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)
Positionly 的 API 资源在这里:
我有兴趣学习如何将 Curl 重写为 Python 请求,或使用类似 PyCurl 的东西来让事情变得更简单。
这是 Curl 代码(我相信,如果我错了请纠正我):
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.
使用请求:
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)