title: Python 3 basic auth with pinnaclesports API
body: <p>i am trying to grab betting lines with python from pinnaclesports using their API  <a href="http://www.pinnaclesports.com/api-xml/manual" rel="nofollow">http://www.pinnaclesports.com/api-xml/manual</a></p>
  
  <p>which requires basic authentication (<a href="http://www.pinnaclesports.com/api-xml/manual#authentication" rel="nofollow">http://www.pinnaclesports.com/api-xml/manual#authentication</a>):</p>
  
  <blockquote>
    <p>Authentication</p>
    
    <p>API use HTTP Basic access authentication . Always use HTTPS to access
    the API. You need to send HTTP Request header like this:</p>
    
    <p>Authorization: Basic 
  
  <pre><code>For example:
  Authorization: Basic U03MyOT23YbzMDc6d3c3O1DQ1
  </code></pre>
  </blockquote>
  
  <pre><code>import urllib.request, urllib.parse, urllib.error
  import socket
  import base64
  
  url = 'https://api.pinnaclesports.com/v1//feed?sportid=12&amp;leagueid=6164'
  username = "abc"
  password = "xyz"
  
  base64 = "Basic: " + base64.b64encode('{}:{}'.format(username,password).encode('utf-8')).decode('ascii')
  print (base64)
  
  details = urllib.parse.urlencode({ 'Authorization' : base64 })
  details = details.encode('UTF-8')
  url = urllib.request.Request(url, details)
  url.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13")    
  responseData = urllib.request.urlopen(url).read().decode('utf8', 'ignore')
  print (responseData)
  </code></pre>
  
  <p>Unfortunately i get a http 500 error. Which from my point means either my authentication isn't working properly or their API is not working.</p>
  
  <p>Thanks in advance</p>