Python - requests.exceptions.SSLError - dh key too small

前端 未结 7 902
梦如初夏
梦如初夏 2020-12-08 14:21

I\'m scraping some internal pages using Python and requests. I\'ve turned off SSL verifications and warnings.

requests.packages.urllib3.disable_warnings()
p         


        
7条回答
  •  猫巷女王i
    2020-12-08 14:57

    this is not an extra answer just try to combine the solution code from question with extra information So others can copy it directly without extra try

    It is not only a DH Key issues in server side, but also lots of different libraries are mismatched in python modules.

    Code segment below is used to ignore those securitry issues because it may be not able be solved in server side. For example if it is internal legacy server, no one wants to update it.

    Besides the hacked string for 'HIGH:!DH:!aNULL', urllib3 module can be imported to disable the warning if it has

    import requests
    import urllib3
    
    requests.packages.urllib3.disable_warnings()
    requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += ':HIGH:!DH:!aNULL'
    try:
        requests.packages.urllib3.contrib.pyopenssl.util.ssl_.DEFAULT_CIPHERS += ':HIGH:!DH:!aNULL'
    except AttributeError:
        # no pyopenssl support used / needed / available
        pass
    
    page = requests.get(url, verify=False)
    

提交回复
热议问题