Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Summon API searches with Python
Search Summon API with Python.
See Dough Chesnut's Code4Lib mailing list post:
import httplib2
import urllib
from datetime import datetime
import hmac
import base64
import hashlib
from pprint import pprint
api_id = 'org'
api_key = 'key'
summonHost = ''
summonPath = '/search'
def summonMkHeaders(querystring):
summonAccessID = api_id
summonSecretKey = api_key
summonAccept = "application/json"
summonThedate = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
summonQS = "&".join(sorted(querystring.split('&')))
summonQS = urllib.unquote_plus(summonQS)
summonIdString = summonAccept + "\n" + summonThedate + "\n" + summonHost + "\n" + summonPath + "\n" + summonQS + "\n"
summonDigest = base64.encodestring(, unicode(summonIdString), hashlib.sha1).digest())
summonAuthstring = "Summon "+summonAccessID+';'+summonDigest
summonAuthstring = summonAuthstring.replace('\n','')
return {'Accept':summonAccept,'x-summon-date':summonThedate,'Host':summonHost,'Authorization':summonAuthstring}
http = httplib2.Http()
url = 'http://%s%s?%s' % (summonHost, summonPath, qstring)
headers = summonMkHeaders(qstring)
print headers
response, content = http.request(url, 'GET', headers=headers)
print response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment