0

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 StringIO
import pycurl, json

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

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

c = pycurl.Curl()
c.setopt(pycurl.URL, apiurl)
c.setopt(pycurl.HTTPHEADER, ['Accept: application/json'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
response = c.perform()
c.close()
print response
1

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.