我正在做这个请求,但它只适用于urllib3和requests库,我猜测这是因为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())