title: Valid, working domain gives "socket.gaierror: [Errno -2] Name or service not known"
body: <p>I'm working on a project in which I need to implement SSO. My SSO OAuth2 credentials are along the lines of:</p>
  
  <pre><code>SECRET = 'abcdefghijklmn12345678'
  ACCESS_TOKEN_URL = "https://myprovider.example.com/as/token.oauth2"
  USER_API_URL = "https://myprovider.example.com/idp/userinfo.openid"
  JWKS_URL = "https://myprovider.example.com/pf/JWKS"
  REDIRECT_URI = "http://localhost/api/1/auth/ping"
  AUTH_ENDPOINT = "https://myprovider.example.com/as/authorization.oauth2"
  </code></pre>
  
  <p>The library I am using has been tested and should work, but for some reason fails with:</p>
  
  <pre><code>[2018-09-13 14:09:29,796] ERROR in app: Exception on /api/1/auth/ping [POST]
  Traceback (most recent call last):
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
      (self._dns_host, self.port), self.timeout, **extra_kw)
    File "/www/lemur/lib/python3.6/site-packages/urllib3/util/connection.py", line 59, in create_connection
      for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
    File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
      for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  socket.gaierror: [Errno -2] Name or service not known
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
      chunked=chunked)
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
      self._validate_conn(conn)
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
      conn.connect()
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
      conn = self._new_conn()
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
      self, "Failed to establish a new connection: %s" % e)
  urllib3.exceptions.NewConnectionError: &lt;urllib3.connection.VerifiedHTTPSConnection object at 0x7fc15ed415f8&gt;: Failed to establish a new connection: [Errno -2] Name or service not known
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/www/lemur/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
      timeout=timeout
    File "/www/lemur/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
      _stacktrace=sys.exc_info()[2])
    File "/www/lemur/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
      raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='myprovider.example.com', port=443): Max retries exceeded with url: /as/token.oauth2?grant_type=authorization_code&amp;scope=openid+email+profile&amp;code=abcdef123-ghijklm456&amp;redirect_uri=http%3A%2F%2Flocalhost%2Fapi%2F1%2Fauth%2Fping&amp;client_id=lemur (Caused by NewConnectionError('&lt;urllib3.connection.VerifiedHTTPSConnection object at 0x7fc15ed415f8&gt;: Failed to establish a new connection: [Errno -2] Name or service not known',))
  </code></pre>
  
  <p>After a bit of debugging, I found that the exception stems from <code>r = requests.post(access_token_url, headers=headers, params=params, verify=verify_cert)</code> within the the SSO library.</p>
  
  <p>I printed out the value of <code>access_token_url</code>, which was <code>https://myprovider.example.com/as/token.oauth2</code>.</p>
  
  <p>Some Googling informed me that <code>socket.gaierror: [Errno -2] Name or service not known</code> may stem from the fact that it was expecting a hostname rather than a URL, ie just <code>myprovider.example.com/as/token.oauth2</code> (without the <code>https://</code>). The hostname <code>myprovider.example.com/as/token.oauth2</code> does not go anywhere, and visiting it on a browser returns a "Could not receive respoonse" message. Visiting <code>https://myprovider.example.com/as/token.oauth2</code> works just fine, however.</p>
  
  <p>My provider requires <code>https://</code> in front (ex <code>https://myprovider.example.com/as/token.oauth2</code>), otherwise I'll receive a "Could not receive response" message from the browser. Even appending port 443 as <code>myprovider.example.com:443/as/token.oauth2</code> will not work. <code>http://myprovider.example.com</code> does not redirect to <code>https</code>, either, and returns the "Could not receive response" message.</p>
  
  <p>Parsing out the <code>https://</code> so <code>access_token_url = 'myprovider.example.com/as/token.oauth2'</code> fails as well.</p>
  
  <p>Could the required use of <code>https://</code> (or, more likely, the inability to go without it) be the issue?</p>
  
  <p>Thanks!</p>