http - How to post XML using digest auth in python? -


i building application following:

  1. post xml http address
  2. take response , store in table on remote mssql db
  3. post xml again , compare response stored in database
  4. look differences, , when present, post xml http address
  5. take new response, , parse needed, sending results mssql table.

the http server uses digest authentication, have had sorts of trouble getting working in python. first forray python , i'm learning kinds of stuff...but can't seem this. have real examples of digest authentication in python? i'd going, , try work through of rest of myself. ideally i'd use cookies keep session open.

thanks!

edit

here have far, , outputs:

url = "https://url.here.com/xml" xml = '''<request method=\"switchvox.currentcalls.getlist\"><parameters></parameters></request>''' user = "user" secret = "secret" realm = "switchvox_api_auth"  passwdmngr = urllib2.httppasswordmgrwithdefaultrealm() passwdmngr.add_password(realm,url,user,secret) authhandler = urllib2.httpdigestauthhandler(passwdmngr) opener = urllib2.build_opener(authhandler)  urllib2.install_opener(opener)  req = urllib2.request(url) req.add_header('content-type', 'application/xml') res = urllib2.urlopen(req, xml)  print res.read 

this back:

<bound method _fileobject.read of <socket._fileobject object @ 0xb75c741c>> 

doesn't seem matter change, that's can out of it. re-working xml lxml; once done check again , report.

edit

changed use lxml, proper printing @ end..

import urllib2 lxml import etree  #defining xml request current calls: #       <request method="switchvox.currentcalls.getlist"> #               <parameters> #               </parameters> #       </request>  request = etree.element("request") parameters = etree.subelement(request, "parameters")  xml = etree.tostring(request, pretty_print=true) url = "https://url.here.com/xml" user = "user" secret = "secret" realm = "switchvox_api_auth"  passwdmngr = urllib2.httppasswordmgrwithdefaultrealm() passwdmngr.add_password(realm,url,user,secret) authhandler = urllib2.httpdigestauthhandler(passwdmngr) opener = urllib2.build_opener(authhandler)  urllib2.install_opener(opener)  req = urllib2.request(url) req.add_header('content-type', 'application/xml') res = urllib2.urlopen(req, xml)  response = res.read() print response 


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -