class urllib.request.FancyURLopener(...)
Deprecated since version 3.3.
FancyURLopener
subclasses URLopener
providing default handling for the following HTTP response codes: 301, 302, 303, 307 and 401. For the 30x response codes listed above, the Location header is used to fetch the actual URL. For 401 response codes (authentication required), basic HTTP authentication is performed. For the 30x response codes, recursion is bounded by the value of the maxtries attribute, which defaults to 10.
For all other response codes, the method http_error_default()
is called which you can override in subclasses to handle the error appropriately.
Note
According to the letter of RFC 2616, 301 and 302 responses to POST requests must not be automatically redirected without confirmation by the user. In reality, browsers do allow automatic redirection of these responses, changing the POST to a GET, and urllib
reproduces this behaviour.
The parameters to the constructor are the same as those for URLopener
.
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.
The FancyURLopener
class offers one additional method that should be overloaded to provide the appropriate behavior:
-
prompt_user_passwd(host, realm)
-
Return information needed to authenticate the user at the given host in the specified security realm. The return value should be a tuple,
(user, password)
, which can be used for basic authentication.The implementation prompts for this information on the terminal; an application should override this method to use an appropriate interaction model in the local environment.
Please login to continue.