htaccess & urllib

Discussion in 'Python' started by Max Khesin, Jul 23, 2003.

  1. Max Khesin

    Max Khesin Guest

    Is there a way to access an htaccess-protected directory with urllib,
    password being known?
    thanks,
    max
    --
    ========================================
    Max Khesin, software developer -

    [check out our image compression software at www.cvisiontech.com, JBIG2-PDF
    compression @
    www.cvisiontech.com/cvistapdf.html]
    Max Khesin, Jul 23, 2003
    #1
    1. Advertising

  2. Max Khesin

    Max Khesin Guest

    thanks!

    --
    ========================================
    Max Khesin, software developer -

    [check out our image compression software at www.cvisiontech.com, JBIG2-PDF
    compression @
    www.cvisiontech.com/cvistapdf.html]


    "Rene Pijlman" <> wrote in
    message news:...
    > Max Khesin:
    > >Is there a way to access an htaccess-protected directory with urllib,
    > >password being known?

    >
    > .htaccess is not a protection mechanism, but a configuration
    > file. If this configuration file specifies HTTP Basic
    > Authentication you can use:
    >
    > "class FancyURLopener(...)
    > basic HTTP authentication is performed ...
    > Note: When performing basic authentication, a FancyURLopener
    > instance calls its prompt_user_passwd() method. The default
    > implementation asks the users for the required information on
    > the controlling terminal. A subclass may override this method to
    > support more appropriate behavior if needed."
    > http://www.python.org/doc/current/lib/module-urllib.html
    >
    > --
    > René Pijlman
    Max Khesin, Jul 23, 2003
    #2
    1. Advertising

  3. Max Khesin

    Rene Pijlman Guest

    Max Khesin:
    >Is there a way to access an htaccess-protected directory with urllib,
    >password being known?


    ..htaccess is not a protection mechanism, but a configuration
    file. If this configuration file specifies HTTP Basic
    Authentication you can use:

    "class FancyURLopener(...)
    basic HTTP authentication is performed ...
    Note: When performing basic authentication, a FancyURLopener
    instance calls its prompt_user_passwd() method. The default
    implementation asks the users for the required information on
    the controlling terminal. A subclass may override this method to
    support more appropriate behavior if needed."
    http://www.python.org/doc/current/lib/module-urllib.html

    --
    René Pijlman
    Rene Pijlman, Jul 23, 2003
    #3
  4. Max Khesin

    John J. Lee Guest

    "Max Khesin" <> writes:

    > Is there a way to access an htaccess-protected directory with urllib,
    > password being known?


    urllib2 is better than urllib.

    From the urllib2 module docstring, cut down a bit (and assuming you
    mean basic HTTP authentication -- HTTPDigestAuthHandler might also be
    of use to you):

    import urllib2

    authinfo = urllib2.HTTPBasicAuthHandler()
    authinfo.add_password('realm', 'host', 'username', 'password')

    opener = urllib2.build_opener(authinfo)

    f = opener.open('http://www.python.org/')

    print f.info() # response headers
    print f.read() # response body


    John
    John J. Lee, Jul 23, 2003
    #4
    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. Stoco

    .htaccess and perl cgi

    Stoco, Jan 12, 2004, in forum: Perl
    Replies:
    0
    Views:
    2,860
    Stoco
    Jan 12, 2004
  2. Steve

    servlet et .htaccess

    Steve, May 6, 2004, in forum: Java
    Replies:
    1
    Views:
    1,169
    Michael Scovetta
    May 6, 2004
  3. Replies:
    1
    Views:
    574
    Michael Wojcik
    May 28, 2005
  4. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    467
    Terry Jones
    Feb 27, 2008
  5. Chris McDonald
    Replies:
    0
    Views:
    284
    Chris McDonald
    Nov 1, 2010
Loading...

Share This Page