Advertisement
Guest User

gost_requests

a guest
Nov 6th, 2019
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import requests
  2. from requests.adapters import HTTPAdapter
  3. from requests.packages.urllib3.util.ssl_ import create_urllib3_context
  4.  
  5. # https://stackoverflow.com/questions/40373115/how-to-select-specific-the-cipher-while-sending-request-via-python-request-modul
  6. CIPHERS = (
  7. 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
  8. 'DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:!aNULL:!eNULL:!MD5:GOST2012-GOST8912-GOST8912'
  9. )
  10.  
  11.  
  12. class GOSTAdapter(HTTPAdapter):
  13. def init_poolmanager(self, *args, **kwargs):
  14. context = create_urllib3_context(ciphers=CIPHERS)
  15. kwargs['ssl_context'] = context
  16. return super(GOSTAdapter, self).init_poolmanager(*args, **kwargs)
  17.  
  18. def proxy_manager_for(self, *args, **kwargs):
  19. context = create_urllib3_context(ciphers=CIPHERS)
  20. kwargs['ssl_context'] = context
  21. return super(GOSTAdapter, self).proxy_manager_for(*args, **kwargs)
  22.  
  23. s = requests.Session()
  24. s.verify = '/etc/ssl/certs/ca-certificates.crt'
  25. s.mount('https://somegostsite', GOSTAdapter())
  26. r = s.get('https://somegostsite')
  27. print(r.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement