c.perform()
doesn't return anything, you need to configure a file-like object to capture the value. A BytesIO
object would do, you can then call .getvalue()
on that after the call completes:
import pycurl
import pprint
import json
from io import BytesIO
c = pycurl.Curl()
data = BytesIO()
c.setopt(c.URL, 'https://mydomainname.com')
c.setopt(c.WRITEFUNCTION, data.write)
c.perform()
dictionary = json.loads(data.getvalue())
pprint.pprint(dictionary["age"])
If you are not married to pycurl
, you might find requests
to be a lot easier:
import pprint
import requests
dictionary = requests.get('https://mydomainname.com').json()
pprint.pprint(dictionary["age"])
Even the standard library urllib.request
module will be easier than using pycurl
:
from urllib.request import urlopen
import pprint
import json
response = urlopen('https://mydomainname.com')
dictionary = json.load(response)
pprint.pprint(dictionary["age"])