My issue is the integration we are using this with I usually use requests not httplib however due to the product we are trying to integrate I have to use httplib and python 2.7.x (not 3.x.x). I am able to make the connection with the basic auth it looks like however I am always getting an http 500 response and I am not sure why, any ideas?
Script Below:
import httplib, urllib
import base64
import string
import json
host = "REST API HOSTNAME"
url = "/rest/alarms/createAlarm"
username = 'UIM USERNAME'
password = 'UIM PASSWORD'
params = ({'source': 'HOSTNAME', 'ss_id': '1.1', 'supp_key': 'supression_key_alarm', 'level':'warning'})
# base64 encode the username and password
auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
webservice = httplib.HTTP(host)
# write your headers
webservice.putrequest("POST", url)
webservice.putheader("Host", host)
webservice.putheader("Content-Type", "application/JSON")
#webservice.putheader("Accept", "application/JSON")
webservice.putheader("Content-length", "%d" % len(json.dumps(params)))
# write the Authorization header like: 'Basic base64encode(username + ':' + password)
webservice.putheader("Authorization", "Basic %s" % auth)
webservice.endheaders()
webservice.send(json.dumps(params))
# get the response
statuscode, statusmessage, header = webservice.getreply()
print "Response: ", statuscode, statusmessage
print "Headers: ", header
res = webservice.getfile().read()
print 'Content: ', res
This is always returning an http 500 error, and I am not sure why. I know the auth is working because if I remove it I get a 4xx error unauthorized. Very strange, anyone have any ideas/suggestions on why it might not be working?