[Twisted-web] Twisted web client digest authentication?

Paul de Vries pc.vries at tip.nl
Fri Dec 2 09:31:41 EST 2011


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 "

    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()
    return finished


More information about the Twisted-web mailing list