简体   繁体   中英

How can I process this API request to Positionly using Python and not Curl?

The API resource for Positionly is here :

I was interested in learning how to re-write Curl into Python requests , or use something like PyCurl to make things easier.

This is the Curl code (I beleive, correct me if I am wrong):

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'

How would this be re-written using Python requests or PyCurl ?

Note: the response should be printed and potentially later saved to a file or something similar. It's no good authenticating or processing a request and then not knowing what the response was!

I am using Python 2.7.

Using requests:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM