import urllib2
handler = urllib2.HTTPBasicAuthHandler()
handler.add_password('AuthName from .htaccess',
'[URL unfurl="true"]www.your.com',[/URL] 'yourusername', 'yourpass')
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
try:
f = urllib2.urlopen( '[URL unfurl="true"]http://www.your.com/path'[/URL] )
except urllib2.HTTPError, e:
if e.code == 401:
print 'not authorized'
elif e.code == 404:
print 'not found'
elif e.code == 503:
print 'service unavailable'
else:
print 'unknown error: '
else:
print 'success'
for line in f:
print line,