SSL bad Handshake Error 10054 “WSAECONNRESET”

后端 未结 3 694
我在风中等你
我在风中等你 2021-02-14 04:22

Notes:

versions

Python 2.7.11 and my requests version is \'2.10.0\'
\'OpenSSL 1.0.2d 9 Jul 2015\'
Please read the below comment by Martijn Piet         


        
3条回答
  •  [愿得一人]
    2021-02-14 04:50

    This snippet works for me (py2.7.11 64bits + requests==2.10.0) on windows7:

    import requests
    import ssl
    import traceback
    import shutil
    from requests.adapters import HTTPAdapter
    from requests.packages.urllib3.poolmanager import PoolManager
    
    
    class MyAdapter(HTTPAdapter):
    
        def init_poolmanager(self, connections, maxsize, block=False):
            self.poolmanager = PoolManager(num_pools=connections,
                                           maxsize=maxsize,
                                           block=block,
                                           ssl_version=ssl.PROTOCOL_TLSv1)
    
    
    if __name__ == "__main__":
        s = requests.Session()
        s.mount('https://', MyAdapter())
        print "Mounted    "
        filename = "N6945016R0626_2016-06-20__INFO_NAS_Pensacola_Base_Access.docx"
        r = s.get(
            "https://www.neco.navy.mil/necoattach/{0}".format(filename), verify=False, stream=True, timeout=120)
    
        if r.status_code == 200:
            with open(filename, 'wb') as f:
                r.raw.decode_content = True
                shutil.copyfileobj(r.raw, f)
    

提交回复
热议问题