I'm trying to get the json response from a curl post into a json object so I can get to the key/value pair inside the json response.
My attempt so far looks something like this:
import pycurl
import json
c = pycurl.Curl()
#c.setopt(c.VERBOSE, True)
c.setopt(c.URL, 'https://some.place/get/token')
c.setopt(c.FOLLOWLOCATION, True)
post_data = {'id': '1q2w3e4r5t',
'secret': 'abcdefghij'}
# Form data must be provided already urlencoded.
postfields = urlencode(post_data)
# Sets request method to POST,
# Content-Type header to application/x-www-form-urlencoded
# and data to send in request body.
c.setopt(c.POSTFIELDS, postfields)
c.perform()
c.close()
This pumps out the json to the terminal screen, but any attempts so far to "get" the actual json returned by the curl command fails. Ideally, I do NOT want to write the json repsonse into a file first, and I'm also not sure if I would be able to "listen" to stdin - as soon as I get this right, it will probably be transformed into a AWS lambda script...
I'm omitting some functions from my actual code - like the encoding etc.