I am using the submit and get functions from the scripts/api/common.py....
I actually found that I just need to add authentication to the calls, so I added this
def authenticate(url, u, p):
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='GALAXY@GHI. Please log in with your Windows account',
uri=url,
user=u,
passwd=p)
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
def make_url( api_key, url, args=None ):
# Adds the API Key to the URL if it's not already there.
if args is None:
args = []
argsep = '&'
if '?' not in url:
argsep = '?'
if '?key=' not in url and '&key=' not in url:
args.insert( 0, ( 'key', api_key ) )
return url + argsep + '&'.join( [ '='.join( t ) for t in args ] )
def get( api_key, url, user, pw ):
# Do the actual GET.
url = make_url( api_key, url )
authenticate(url, user, pw)
try:
return simplejson.loads( urllib2.urlopen( url ).read() )
except simplejson.decoder.JSONDecodeError, e:
print "URL did not return JSON data"
sys.exit(1)
.
.
.