I would like to modify following code to run use 'requests' module. I have the following code which is working on a website:
def post(url, message, key, sign):
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.SSL_VERIFYPEER, 0)
curl.setopt(pycurl.SSL_VERIFYHOST, 0)
buf = cStringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, buf.write)
curl.setopt(pycurl.POSTFIELDS, message)
curl.setopt(pycurl.HTTPHEADER, ['Key:' + key,
'Sign:' + (sign)])
curl.perform()
response = buf.getvalue()
buf.close()
return response
I tried accessing the website with requests and got rejected on invalid request values using following code:
def post(url, message, key, sign):
import requests
session = requests.session()
session.headers = {'Key': key, 'Sign': sign}
response = session.post(url, message)
return response
What am I doing wrong that these methods don't behave the same?
Thank you.