views:

110

answers:

1

I want to write a simple SSL HTTP client in Python and have heard about the Twisted framework.

I need to be able to authenticate with a REST service - so I was thinking I'd just POST a user name and password to the target server. Assuming authentication is successful, the client will receive a cookie.

Will an HTTP client built on Twisted automatically resend the cookie header for each subsequent request, or do I need to do something special? I've never used Twisted before.

Thanks

+1  A: 

Will an HTTP client built on Twisted automatically resend the cookie header for each subsequent request, or do I need to do something special?

"an HTTP client built on Twisted" will do anything it is built to do - just like, presumably any X built on any Y will do whatever it was built to do. :) So I might suggest that this isn't the question you really care about the answer to.

twisted.web.client.getPage accepts a cookies argument which does two things:

  • it defines the cookies which will be sent with the request
  • it reports what cookies the server wants the client to have set, by being modified to reflect that information (ie, cookies may be added to it or deleted from it)

So if you use getPage and pass around a cookies dictionary that you keep for each request, your authentication problems should be taken care of.

The newer twisted.web.client.Agent could also be made to do this, but currently you'd have to implement the cookie handling part of things yourself.

Jean-Paul Calderone