为什么这个HTTPS请求仅适用于urllib3并请求库?



我正在发出此请求,它仅适用于urllib3和请求库,我猜这是因为SSL版本或证书验证。 任何线索将不胜感激。

这行得通

import urllib3
params = {...}
http = urllib3.PoolManager(cert_reqs='CERT_NONE', assert_hostname=False)
r = http.request("POST", "https://android.clients.google.com/auth" , fields=params)
print(r.data)

此返回Error=BadAuthentication

from urllib import request, parse
import urllib
params = {...}
data = parse.urlencode(params).encode()
req = request.Request("https://android.clients.google.com/auth", data=data)
try:
resp = request.urlopen(req)
print(resp.read())
except urllib.error.HTTPError as e:
print("error", e.read())

使用此代码的密码存在问题,对我有用

from urllib import request, parse
import urllib
import ssl
params = {...}
data = parse.urlencode(params).encode()
req = request.Request("https://android.clients.google.com/auth" , data=data) # this will make the method "POST"
DEFAULT_CIPHERS = ':'.join([
'TLS13-AES-256-GCM-SHA384',
'TLS13-CHACHA20-POLY1305-SHA256',
'TLS13-AES-128-GCM-SHA256',
'ECDH+AESGCM',
'ECDH+CHACHA20',
'DH+AESGCM',
'DH+CHACHA20',
'ECDH+AES256',
'DH+AES256',
'ECDH+AES128',
'DH+AES',
'RSA+AESGCM',
'RSA+AES',
'!aNULL',
'!eNULL',
])
ssl_context = ssl.SSLContext()
if getattr(ssl_context, 'supports_set_ciphers', True):  # Platform-specific: Python 2.6
ssl_context.set_ciphers(DEFAULT_CIPHERS)
try:
resp = request.urlopen(req, context=ssl_context)
print(resp.read())
except urllib.error.HTTPError as e:
print("error", e.read())

相关内容

  • 没有找到相关文章

最新更新