python 具有基本身份验证的urllib示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 具有基本身份验证的urllib示例相关的知识,希望对你有一定的参考价值。

# just an example for me to remember
import urllib2, base64

username = "testuser"
password = "changeme"
url = "https://example.com/"

request = urllib2.Request(url)
b64auth = base64.standard_b64encode("%s:%s" % (username,password))
request.add_header("Authorization", "Basic %s" % b64auth)
result = urllib2.urlopen(request)
print(result.read())

以上是关于python 具有基本身份验证的urllib示例的主要内容,如果未能解决你的问题,请参考以下文章

具有基本身份验证的 Android OkHttp

python 具有基本身份验证的Python 3 HTTP Server

python urllib3 或请求使用应用程序 ID 和应用程序令牌进行身份验证

具有基本身份验证和自定义 UserDetailsS​​ervice 的 Spring Boot OAuth2

带有身份验证的 urllib.request.urlopen(url)

使用 urllib 进行身份验证