Skip to content

Instantly share code, notes, and snippets.

@aerostitch
Created April 21, 2016 09:23
Show Gist options
  • Save aerostitch/35b75b16164a034aca1d457b0462ab1a to your computer and use it in GitHub Desktop.
Save aerostitch/35b75b16164a034aca1d457b0462ab1a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib2
import base64
import json
try:
url = 'https://localhost:15671/api/overview'
username = 'rabbitmquser'
password = 'rabbitmqpwd'
request = urllib2.Request(url)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)
print 'response headers: "%s"' % response.info()
print 'response body:'
print json.dumps(json.loads(response.read()), sort_keys=True, indent=4)
except IOError, e:
if hasattr(e, 'code'): # HTTPError
print 'http error code: ', e.code
elif hasattr(e, 'reason'): # URLError
print "can't connect, reason: ", e.reason
else:
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment