2

I'm attempting to use requests to access a remote server over SSL. Unfortunately it's misconfigured such that it responds with the error TLSV1_UNRECOGNIZED_NAME during the SNI handshake, which is ignored by browsers but raises an exception in requests.

This appears to be the same issue as this question, but in Python rather than Java: SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0`

The connection works perfectly in Python 2, which doesn't support SNI. How can I disable SNI in Python 3 so that the connection works?

Community
  • 1
  • 1
user686782
  • 992
  • 1
  • 10
  • 18
  • Not sure, if it relates, but today I got accross `requests_toolbelt` offereing [SSLAdapter](https://toolbelt.readthedocs.org/en/latest/user.html#ssladapter). – Jan Vlcinsky Jul 21 '14 at 22:02

1 Answers1

7

I couldn't find a way to disable SNI on the requests level, but I found a hack that will trick it into thinking SNI isn't supported. Add this code before importing requests (not after, or it will be too late):

import ssl
ssl.HAS_SNI = False
user686782
  • 992
  • 1
  • 10
  • 18