[Tutor] urllib2_realm??
Kent Johnson
kent37 at tds.net
Wed Apr 11 13:42:58 CEST 2007
govind goyal wrote:
>
> Hi,
>
> Use of Basic HTTP Authentication:
>
> import urllib2
> auth_handler.add_password(*'realm'*, 'host', 'username', 'password')
>
> What is realm and its use in above line of code?
Realm is set by the host. It is usually displayed in the login dialog in
a browser, it will look like a site name.
The realm is in the headers received back from the server. For example:
$ curl -I http://xxx.com/
HTTP/1.1 401 Authorization Required
Date: Wed, 11 Apr 2007 01:39:47 GMT
Server: Apache/2.0.52 (Red Hat) mod_python/3.2.8 Python/2.4.4
WWW-Authenticate: Basic realm="xxxx"
Content-Type: text/html; charset=iso-8859-1
Vary: Accept-Encoding,User-Agent
>
> If I want to access a web page and I don't know what the realm is,then what should I write in place of realm?
I think you can instantiate the HTTPBasicAuthHandler with an instance of
HTTPPasswordMgrWithDefaultRealm. Then pass None as the realm and it will
be used as the default.
Kent
More information about the Tutor
mailing list