title: Seemingly Random ssl.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error
body: <p><strong>Goal:</strong> To auth into an API consistently using python's request library locally.</p>
  <p>Currently, I successfully auth at what seems to be random chunks of 20-30mins throughout the day. The remaining attempts receive an error:</p>
  <pre><code>ssl.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error
  </code></pre>
  <p>In addition, when I push this to AWS and execute from there--no issues.</p>
  <p><strong>Trace:</strong></p>
  <pre><code>  File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 699, in urlopen
      httplib_response = self._make_request(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 382, in _make_request
      self._validate_conn(conn)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 1010, in _validate_conn
      conn.connect()
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connection.py&quot;, line 411, in connect
      self.sock = ssl_wrap_socket(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\util\ssl_.py&quot;, line 428, in ssl_wrap_socket
      ssl_sock = _ssl_wrap_socket_impl(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\util\ssl_.py&quot;, line 472, in _ssl_wrap_socket_impl
      return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
    File &quot;C:\Users\Austin\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 500, in wrap_socket
      return self.sslsocket_class._create(
    File &quot;C:\Users\Austin\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 1040, in _create
      self.do_handshake()
    File &quot;C:\Users\Austin\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 1309, in do_handshake
      self._sslobj.do_handshake()
  ssl.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1123)
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\adapters.py&quot;, line 439, in send
      resp = conn.urlopen(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 755, in urlopen
      retries = retries.increment(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\util\retry.py&quot;, line 573, in increment
      raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='blacknotchportal.com', port=443): Max retries exceeded with url: /Bnotchsvc/Bnotchsvc.svc/Login (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1123)')))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 169, in api_auth
      resp_login = requests.post(url + &quot;/Login&quot;, json=login_params)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\api.py&quot;, line 119, in post
      return request('post', url, data=data, json=json, **kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\api.py&quot;, line 61, in request
      return session.request(method=method, url=url, **kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\sessions.py&quot;, line 542, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\sessions.py&quot;, line 655, in send
      r = adapter.send(request, **kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\adapters.py&quot;, line 514, in send
      raise SSLError(e, request=request)
  requests.exceptions.SSLError: HTTPSConnectionPool(host='blacknotchportal.com', port=443): Max retries exceeded with url: /Bnotchsvc/Bnotchsvc.svc/Login (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1123)')))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 43, in main
      token = api_auth(url, login_params)
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 175, in api_auth
      raise Exception(&quot;Exception occurred during auth, check logs for details&quot;)
  Exception: Exception occurred during auth, check logs for details
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 699, in urlopen
      httplib_response = self._make_request(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 382, in _make_request
      self._validate_conn(conn)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 1010, in _validate_conn
      conn.connect()
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connection.py&quot;, line 411, in connect
      self.sock = ssl_wrap_socket(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\util\ssl_.py&quot;, line 428, in ssl_wrap_socket
      ssl_sock = _ssl_wrap_socket_impl(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\util\ssl_.py&quot;, line 472, in _ssl_wrap_socket_impl
      return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
    File &quot;C:\Users\Austin\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 500, in wrap_socket
      return self.sslsocket_class._create(
    File &quot;C:\Users\Austin\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 1040, in _create
      self.do_handshake()
    File &quot;C:\Users\Austin\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 1309, in do_handshake
      self._sslobj.do_handshake()
  ssl.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1123)
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\adapters.py&quot;, line 439, in send
      resp = conn.urlopen(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\connectionpool.py&quot;, line 755, in urlopen
      retries = retries.increment(
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\urllib3\util\retry.py&quot;, line 573, in increment
      raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='blacknotchportal.com', port=443): Max retries exceeded with url: /Bnotchsvc/Bnotchsvc.svc/Login (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1123)')))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 169, in api_auth
      resp_login = requests.post(url + &quot;/Login&quot;, json=login_params)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\api.py&quot;, line 119, in post
      return request('post', url, data=data, json=json, **kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\api.py&quot;, line 61, in request
      return session.request(method=method, url=url, **kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\sessions.py&quot;, line 542, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\sessions.py&quot;, line 655, in send
      r = adapter.send(request, **kwargs)
    File &quot;C:\Users\Austin\Desktop\Code\atlas\venv\lib\site-packages\requests\adapters.py&quot;, line 514, in send
      raise SSLError(e, request=request)
  requests.exceptions.SSLError: HTTPSConnectionPool(host='blacknotchportal.com', port=443): Max retries exceeded with url: /Bnotchsvc/Bnotchsvc.svc/Login (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1123)')))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 265, in &lt;module&gt;
      main()
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 46, in main
      token = api_auth(url, login_params)
    File &quot;C:/Users/Austin/Desktop/Code/atlas/src/main.py&quot;, line 175, in api_auth
      raise Exception(&quot;Exception occurred during auth, check logs for details&quot;)
  Exception: Exception occurred during auth, check logs for details
  </code></pre>
  <p>I have tried all the other solutions I could find: python version, OPENSSL version, windows firewall, changing crypto standards, forcing different versions of TLS etc.</p>
  <p><strong>python 3.8; requests==2.25.1</strong></p>
  <pre><code>import ssl
  print(ssl.OPENSSL_VERSION)
  
  OpenSSL 1.1.1g  21 Apr 2020
  </code></pre>
  <p><strong>Code:</strong></p>
  <pre><code>import requests
  import json
  import logging
  
  
  def api_auth(url: str, login_params: dict) -&gt; str:
      &quot;&quot;&quot;
      :param url: url to call
      :param login_params: parameters required for login
      :return: a token for auth in future api calls
      &quot;&quot;&quot;
      try:
          resp_login = requests.post(url + &quot;/Login&quot;, json=login_params)
          resp_data = json.loads(resp_login.text)
          print(resp_data)
          token = str(resp_data[&quot;token&quot;])
      except Exception as e:
          logging.exception(&quot;Exception occurred during auth&quot;)
          raise
  
      return token
  
  
  try:
      token = api_auth(url, login_params)
  except:
      logging.info('attempting reauth')
      token = api_auth(url, login_params)
  
  </code></pre>