Authentication session with urllib2

Discussion in 'Python' started by Ken Seehart, Nov 11, 2009.

  1. Ken Seehart

    Ken Seehart Guest

    I'm having some difficulty implementing a client that needs to maintain
    an authenticated https: session.

    I'd like to avoid the approach of receiving a 401 and resubmit with
    authentication, for two reasons:

    1. I control the server, and it was easy for me to make a url that
    receives a POST with username, password and authenticates the session.
    The server keeps a session correctly when I test with a browser. This
    part works fine.

    2. I don't want to send every request twice. See
    http://bugs.python.org/issue7159 There's no reason why I should have to
    do this since I have the ability to keep the server simple.

    What I would really like to do is send one request with the username and
    password to establish the session, and then make multiple authenticated
    requests where the session information remembers the authentication.

    Is there a way to make this happen in python 2.5.2?

    Keep in mind that this only needs to work with a particular server which
    I control. It does not need to function as a general purpose browser.
    The server is powered by Django.

    - Ken
     
    Ken Seehart, Nov 11, 2009
    #1
    1. Advertising

  2. Ken Seehart

    Jon Clements Guest

    On 11 Nov, 07:02, Ken Seehart <> wrote:
    > I'm having some difficulty implementing a client that needs to maintain
    > an authenticated https: session.
    >
    > I'd like to avoid the approach of receiving a 401 and resubmit with
    > authentication, for two reasons:
    >
    > 1. I control the server, and it was easy for me to make a url that
    > receives a POST with username, password and authenticates the session.  
    > The server keeps a session correctly when I test with a browser.  This
    > part works fine.
    >
    > 2. I don't want to send every request twice.  Seehttp://bugs.python.org/issue7159 There's no reason why I should have to
    > do this since I have the ability to keep the server simple.
    >
    > What I would really like to do is send one request with the username and
    > password to establish the session, and then make multiple authenticated
    > requests where the session information remembers the authentication.
    >
    > Is there a way to make this happen in python 2.5.2?
    >
    > Keep in mind that this only needs to work with a particular server which
    > I control.  It does not need to function as a general purpose browser.  
    > The server is powered by Django.
    >
    > - Ken


    How about http://docs.djangoproject.com/en/dev/topics/auth/ and using
    a urllib2 opener with cookie support ala some examples on
    http://personalpages.tds.net/~kent37/kk/00010.html ?

    hth,
    Jon.
     
    Jon Clements, Nov 11, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andre Bocchini

    Proxy Authentication using urllib2

    Andre Bocchini, Sep 20, 2003, in forum: Python
    Replies:
    2
    Views:
    851
    Myles
    Sep 23, 2003
  2. Fuzzyman

    Authentication from urllib2

    Fuzzyman, Oct 23, 2004, in forum: Python
    Replies:
    1
    Views:
    501
    Michael Foord
    Oct 23, 2004
  3. news.corp.adobe.com
    Replies:
    1
    Views:
    1,512
    deelan
    Jul 8, 2005
  4. Josef Cihal
    Replies:
    0
    Views:
    771
    Josef Cihal
    Sep 5, 2005
  5. Ray Slakinski
    Replies:
    1
    Views:
    748
    John J. Lee
    Nov 8, 2005
Loading...

Share This Page