I need to perform http PUT operations from python. What libraries have been proven to support this? In particular, I need to execute PUT on keyboards, and not upload files.
I try to work with restful_lib.py, but I get incorrect results from the API that I am testing. (I know that the results are invalid because I can run the same query using curl from the command line and it works.)
After visiting Pycon 2011, I got the impression that pycurl might be my solution, so I tried to implement this. I have two questions. First, pycurl renames "PUT" as "UPLOAD", which apparently implies that it focuses on downloading files, rather than key pairs. Secondly, when I try to use it, I never get a return from the .perform () step.
Here is my current code:
import pycurl
import urllib
url='https://xxxxxx.com/xxx-rest'
UAM=pycurl.Curl()
def on_receive(data):
print data
arglist= [\
('username', 'testEmailAdd@test.com'),\
('email', 'testEmailAdd@test.com'),\
('username','testUserName'),\
('givenName','testFirstName'),\
('surname','testLastName')]
encodedarg=urllib.urlencode(arglist)
path2= url+"/user/"+"99b47002-56e5-4fe2-9802-9a760c9fb966"
UAM.setopt(pycurl.URL, path2)
UAM.setopt(pycurl.POSTFIELDS, encodedarg)
UAM.setopt(pycurl.SSL_VERIFYPEER, 0)
UAM.setopt(pycurl.UPLOAD, 1)
UAM.setopt(pycurl.CONNECTTIMEOUT, 1)
UAM.setopt(pycurl.TIMEOUT, 2)
UAM.setopt(pycurl.WRITEFUNCTION, on_receive)
print "about to perform"
print UAM.perform()
source
share