当前位置:网站首页 > 技术博客 > 正文

urllib包



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.

  • 上一篇: usb协议原理
  • 下一篇: phython基础语法教程
  • 版权声明


    相关文章:

  • usb协议原理2024-12-15 22:30:04
  • java并发编程从入门到精通2024-12-15 22:30:04
  • 平滑处理设置多少最好2024-12-15 22:30:04
  • srand和rand函数2024-12-15 22:30:04
  • 安全测试包含哪些内容2024-12-15 22:30:04
  • phython基础语法教程2024-12-15 22:30:04
  • 结构体C语言2024-12-15 22:30:04
  • 结构体指针typedef2024-12-15 22:30:04
  • md5 linux命令2024-12-15 22:30:04
  • 路由交换相关知识2024-12-15 22:30:04