python - How can i execute the following code using pycurl -


curl https://api.smartsheet.com/1.1/sheets -h "authorization: bearer 26lhbngfsybdayabz6afrc6dcd" -h "content-type: application/json" -x post -d @test.json 

if new coding, don't use pycurl considered obsolete. instead use requests can installed pip install requests.

here how equivalent requests:

import requests  open('test.json') data:     headers = {'authorization': 'bearer 26lhbngfsybdayabz6afrc6dcd'                'content-type' : 'application/json'}     r = requests.post('https://api.smartsheet.com/1.1/sheets', headers=headers, data=data) print r.json 

if must use pycurl suggest start reading here. done (untested) code:

import pycurl  open('test.json') json:     data = json.read()      c = pycurl.curl()     c.setopt(pycurl.url, 'https://api.smartsheet.com/1.1/sheets')     c.setopt(pycurl.post, 1)     c.setopt(pycurl.postfields, data)     c.setopt(pycurl.httpheader, ['authorization: bearer 26lhbngfsybdayabz6afrc6dcd',                                  'content-type: application/json'])     c.perform() 

this shows requests far more elegant.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -