title: Python Requests Authentication
body: <p>I'm trying to interact with an API via Python3's Requests module but the authentication is not working . I am able to take the exact same url with the same username/password and use the API via my Firefox browser.</p>
  
  <p>There are a few complications with the setup, so let me explain. </p>
  
  <ol>
  <li><p>The device I'm trying to talk with uses https but I don't have access to the certs so I'm choosing not to verify. I'm able to interact with Requests with older models that only use http no problem.</p></li>
  <li><p>The device is on a local network but my company's network utilizes proxies that interfere with communication to devices on a local network so I turn these off.</p></li>
  </ol>
  
  <p>Here's an example of my code:</p>
  
  <pre><code>session = requests.Session() 
  auth = ('username', 'password')
  session.auth = auth 
  s.trust_env = False # remove proxies (see 2 above)
  response = session.get(
        url='https://mylocalurl/api/',
        params={'apikey' : 'myapikey',
                  'req' : 'generalInfo'},
        verify=False # don't verify SSL cert (see 1 above)
  )
  </code></pre>
  
  <p>My first thought was that I had to specify the encoding of the credentials sent since I'm able to use those in my browser. I've tried doing <code>auth = (b'username', b'password')</code> with no luck. I looked at the <code>response.content</code> and found <code>b'&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;\n</code> in the first line so I tried specifying that by <code>auth = ('username'.encode('iso-8859-1'), 'password'.encode('iso-8859-1'))</code> but still no luck. </p>
  
  <p>The questions I have are:</p>
  
  <ul>
  <li>The API's server is LightTPD, is there something particular with authenticating with this server via Python that I'm missing?</li>
  <li>Do I have to verify my SSL cert to authenticate? Wouldn't make sense but I'm asking anyway.</li>
  <li>Is there any more information I could gleam from the 401 response that could help me determine how to send the credentials in a way the server will accept?</li>
  </ul>