Skip to content Skip to sidebar Skip to footer

Sending Url Data Curl/json In Python

I am trying use curl in python with url parameter but it is returning 'None', same api with same parameter in php it is working fine. Here is my python code : from StringIO import

Solution 1:

Try this

import StringIO
import pycurl, json

fout = StringIO.StringIO()

apiurl = 'http://servername.com:7705'

data = json.dumps({"node": "test", "type": "get_by_field"})

c = pycurl.Curl()
c.setopt(pycurl.WRITEFUNCTION, fout.write)

c.setopt(pycurl.URL, apiurl)
c.setopt(pycurl.HTTPHEADER, ['Accept: application/json'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
c.perform()
c.getinfo(pycurl.RESPONSE_CODE)
fout.getvalue()

Post a Comment for "Sending Url Data Curl/json In Python"