To illustrate creating and installing a handler we will use the . For a more detailed discussion of this subject -- including an explanation of how Basic Authentication works - see the .
When authentication is required, the server sends a header (as well as the 401 error code) requesting authentication. This specifies the authentication scheme and a 'realm'. The header looks like: .
例如
The client should then retry the request with the appropriate name and password for the realm included as a header in the request. This is 'basic authentication'. In order to simplify this process we can create an instance of and an opener to use this handler.
The uses an object called a password manager to handle the mapping of URLs and realms to passwords and usernames. If you know what the realm is (from the authentication header sent by the server), then you can use a . Frequently one doesn't care what the realm is. In that case, it is convenient to use . This allows you to specify a default username and password for a URL. This will be supplied in the absence of you providing an alternative combination for a specific realm. We indicate this by providing as the realm argument to the method.
The top-level URL is the first URL that requires authentication. URLs "deeper" than the URL you pass to .add_password() will also match.
is in fact either a full URL (including the 'http:' scheme component and the hostname and optionally the port number) e.g. or an "authority" (i.e. the hostname, optionally including the port number) e.g. or (the latter example includes a port number). The authority, if present, must NOT contain the "userinfo" component - for example is not correct.
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/9497.html