Hi
Made something that connects to a httpserver and parses the xml stream it sends. The webserver it has to connect to uses digest authentication.
How can I implement digest authentication in this?
thanks in advance
the code I put together:
from twisted.internet import reactor from twisted.internet.defer import Deferred from twisted.internet.protocol import Protocol from twisted.web.client import Agent from twisted.web.http_headers import Headers from StringIO import StringIO from elementtree import ElementTree
class ParseReceived(Protocol): def __init__(self, finished): self.finished = finished self.dataStream = StringIO()
def dataReceived(self, bytes): display = bytes #print 'some data received:' #print display context = ElementTree.iterparse(StringIO(bytes), events = ("start", "end")) context = iter(context) event, root = context.next()
for event, elem in context: if elem.tag == "Tag": print "Tag " root.clear()
def connectionLost(self, reason): print 'finished receiving', reason.getErrorMessage()
agent = Agent(reactor)
d = agent.request('GET', 'http:someadress', Headers({'User-Agent': ['Twisted web client']}), None)
def cbResponse(response): print 'Response version: ', response.version finished = Deferred() response.deliverBody(ParseReceived(finished)) return finished
d.addCallback(cbResponse) reactor.run()
On 2 Dec, 02:31 pm, pc.vries@tip.nl wrote:
Hi
Made something that connects to a httpserver and parses the xml stream it sends. The webserver it has to connect to uses digest authentication.
How can I implement digest authentication in this?
Digest authentication is performed in the headers of requests and responses. The server sends a challenge, the client computes a response proving they know a secret only one user is supposed to know.
[snip]
def cbResponse(response):
The response object has all of the headers sent from the server. You can inspect them and then compute the appropriate challenge response to include in your *next* request. If you get it right, then the server will give you the content instead of sending you a challenge.
Some work has been done on adding higher-level support for this feature to Twisted, but it is not yet complete. You can follow its progress or pitch in at http://twistedmatrix.com/trac/ticket/5148.
Jean-Paul
print 'Response version: ', response.version finished = Deferred() response.deliverBody(ParseReceived(finished)) return finished
d.addCallback(cbResponse) reactor.run() _______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Thanks for setting me on the right track. This is the first and (so far) only response I got so I supposed it was a stupid or impossible question. Which is very likely because I'm new to python and twisted.
Paul
Op 5 dec 2011, om 14:51 heeft exarkun@twistedmatrix.com het volgende geschreven:
On 2 Dec, 02:31 pm, pc.vries@tip.nl wrote:
Hi
Made something that connects to a httpserver and parses the xml stream it sends. The webserver it has to connect to uses digest authentication.
How can I implement digest authentication in this?
Digest authentication is performed in the headers of requests and responses. The server sends a challenge, the client computes a response proving they know a secret only one user is supposed to know.
[snip]
def cbResponse(response):
The response object has all of the headers sent from the server. You can inspect them and then compute the appropriate challenge response to include in your *next* request. If you get it right, then the server will give you the content instead of sending you a challenge.
Some work has been done on adding higher-level support for this feature to Twisted, but it is not yet complete. You can follow its progress or pitch in at http://twistedmatrix.com/trac/ticket/5148.
Jean-Paul
print 'Response version: ', response.version finished = Deferred() response.deliverBody(ParseReceived(finished)) return finished
d.addCallback(cbResponse) reactor.run() _______________________________________________