-1

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.

Studiumcirclus
  • 69
  • 4
  • 11
  • 1
    You should make some effort to do this yourself before asking. SO is not a code writing service. – Paul Rooney Apr 06 '17 at 09:20
  • I'm voting to close this question as off-topic because SO is not a code translation service. – TigerhawkT3 Apr 06 '17 at 09:58
  • I can see that maybe my question could have given more detail. I've actually opted to install Postman which is helping me to understand APIs more. It allows me to import API calls from many languages (PHP, Python, Curl) and then lays it all out in a nice GUI which is helping to teach me the relationships between request and responses. The different areas which need to be filled (body, header) and the types of request (POST / GET). I actually want to thank you guys for incentivising me to learn more! Someone answered the question, the example Flurin gave may help someone else :) – Studiumcirclus Apr 06 '17 at 10:57

1 Answers1

2

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)
Flurin
  • 681
  • 5
  • 14
  • Thanks for this! Combining this with a tool which is helping to teach me much more about APIs ("Postman") I think I have what I need to begin writing requests I'd actually use rather than the 'example' request given. – Studiumcirclus Apr 06 '17 at 11:01