【问题标题】:why this https request only works with urllib3 and requests libraries?为什么这个 https 请求只适用于 urllib3 和请求库?
【发布时间】:2020-09-28 05:36:15
【问题描述】:

我正在提出这个请求,它只适用于 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())

【问题讨论】:

    标签: python curl python-requests urllib urllib3


    【解决方案1】:

    使用此代码的密码对我有用

    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())
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2020-04-11
      • 2017-06-27
      • 2020-08-27
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多