Skip to content

Instantly share code, notes, and snippets.

@j4mie
Created October 17, 2011 16:03
Show Gist options
  • Save j4mie/1292957 to your computer and use it in GitHub Desktop.
Save j4mie/1292957 to your computer and use it in GitHub Desktop.
None-working Codebase API code
import requests
key = 'xxxx' # API key copied from https://dabapps.codebasehq.com/settings/profile
auth = ('dabapps/j4mie', key)
headers = {
'Accept': 'application/xml',
'Content-type': 'application/xml',
}
response = requests.get('http://api3.codebasehq.com/projects', auth=auth, headers=headers)
print response.status_code # prints 403
@j4mie
Copy link
Author

j4mie commented Oct 17, 2011

Solution from codebase support:

import requests
import base64

key = 'xxxx' # API key copied from https://dabapps.codebasehq.com/settings/profile

headers = {
    'Accept': 'application/xml',
    'Content-type': 'application/xml',
    'Authorization': base64.encodestring('%s:%s' % ('dabapps/j4mie', key)).replace('\n', ''),
}

response = requests.get('http://api3.codebasehq.com/projects', headers=headers)

print response.status_code # prints 200 - happy times

@j4mie
Copy link
Author

j4mie commented Oct 23, 2011

Note: this is no longer required with the latest version of Requests (0.7.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment