HTTPDigestAuthHandler could not be used as Gmail feed does not use digest authentication.
Digest authentication constists of the realm's (typically a description of the computer or system being accessed) and the password's MD5 (or other algorithm) digest. To check if a password protected page uses Basic Auth or Digest Auth simply:
I don't use HTTPBasicAuthHandler because it requires the specific realm ('New mail feed' for Gmail) otherwise it won't get authorized.
The example shown at urllib2 manual (http://docs.python.org/library/urllib2.html) needs the specific realm or it fails.
import urllib2
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='PDQ Application', uri='https://mahler:8092/site-updates.py', user='klem', passwd='kadidd!ehopper')
opener = urllib2.build_opener(auth_handler)
If we use that method we need first to acquire the right realm and then proceed to the login.
>>> import feedparser, re
>>> d = feedparser.parse('http://feedparser.org/docs/examples/basic_auth.xml')
>>> d.status
401
>>> d.headers['www-authenticate']
'Basic realm="BasicTest"'
>>> realm = re.findall('realm="([^"]*)"', d.headers['www-authenticate'])[0]
>>> realm
'BasicTest'
HTTPDigestAuthH andler could not be used as Gmail feed does not use digest authentication.
Digest authentication constists of the realm's (typically a description of the computer or system being accessed) and the password's MD5 (or other algorithm) digest. To check if a password protected page uses Basic Auth or Digest Auth simply:
>>> import feedparser feedparser. org/docs/ examples/ digest_ auth.xml') 'www-authentica te'] feedparser. org/docs/ examples/ digest_ auth.xml') 'www-authentica te'] "+LV/uLLdAwA= 5d77397291261b9 ef256b034e19bcb 94f5b7992a" ,
>>> d = feedparser.parse('http://
>>> d.status
401
>>> d.headers[
'Basic realm="Use test/basic"'
>>> d = feedparser.parse('http://
>>> d.status
401
>>> d.headers[
'Digest realm="DigestTest",
nonce=
algorithm=MD5,
qop="auth"'
As you see from the example above, the authentication method is stated in the response headers. en.wikipedia. org/wiki/ Digest_ access_ authentication).
For more information on Digest Authentication look here (http://
I don't use HTTPBasicAuthHa ndler because it requires the specific realm ('New mail feed' for Gmail) otherwise it won't get authorized. docs.python. org/library/ urllib2. html) needs the specific realm or it fails.
The example shown at urllib2 manual (http://
import urllib2 HTTPBasicAuthHa ndler() add_password( realm=' PDQ Application',
uri= 'https:/ /mahler: 8092/site- updates. py',
user= 'klem',
passwd= 'kadidd! ehopper' ) build_opener( auth_handler)
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.
auth_handler.
opener = urllib2.
If we use that method we need first to acquire the right realm and then proceed to the login. feedparser. org/docs/ examples/ basic_auth. xml') 'www-authentica te'] 'realm= "([^"]* )"', d.headers[ 'www-authentica te'])[0]
>>> import feedparser, re
>>> d = feedparser.parse('http://
>>> d.status
401
>>> d.headers[
'Basic realm="BasicTest"'
>>> realm = re.findall(
>>> realm
'BasicTest'
I applied the suggested changes.