By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,285 Members | 2,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,285 IT Pros & Developers. It's quick & easy.

htaccess & urllib

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

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a
thanks!

--
========================================
Max Khesin, software developer -
ma*@cNvOiSsPiAoMntech.com
[check out our image compression software at www.cvisiontech.com, JBIG2-PDF
compression @
www.cvisiontech.com/cvistapdf.html]
"Rene Pijlman" <re********************@my.address.is.invalid> wrote in
message news:tn********************************@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

Jul 18 '05 #3

P: n/a
"Max Khesin" <ma*@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
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.