Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   htaccess & urllib (http://www.velocityreviews.com/forums/t320039-htaccess-and-urllib.html)

Max Khesin 07-23-2003 03:42 PM

htaccess & urllib
 
Is there a way to access an htaccess-protected directory with urllib,
password being known?
thanks,
max
--
========================================
Max Khesin, software developer -
max@cNvOiSsPiAoMntech.com
[check out our image compression software at www.cvisiontech.com, JBIG2-PDF
compression @
www.cvisiontech.com/cvistapdf.html]




Max Khesin 07-23-2003 03:53 PM

Re: htaccess & urllib
 
thanks!

--
========================================
Max Khesin, software developer -
max@cNvOiSsPiAoMntech.com
[check out our image compression software at www.cvisiontech.com, JBIG2-PDF
compression @
www.cvisiontech.com/cvistapdf.html]


"Rene Pijlman" <reply.in.the.newsgroup@my.address.is.invalid> wrote in
message news:tnbthvorrrc59nn3689ue741lvtb0horke@4ax.com...
> 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/li...le-urllib.html
>
> --
> René Pijlman




Rene Pijlman 07-23-2003 03:55 PM

Re: htaccess & urllib
 
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/li...le-urllib.html

--
René Pijlman

John J. Lee 07-23-2003 04:28 PM

Re: htaccess & urllib
 
"Max Khesin" <max@cNOvSisiPonAtecMh.com> 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


All times are GMT. The time now is 07:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.