I am trying to build a Python 3 service that calls the ActiveMQ REST management API provided by Jolokia, but I get a 401 Unauthorized
response. My guess is that I am passing the authentication data wrong. Unfortunately, the ActiveMQ REST documentation example with curl
or wget
doesn't really help much.
import urllib.parse
import urllib.request
url = 'http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost,service=Health'
data = dict(user='admin', password='admin')
encoded_data = urllib.parse.urlencode(data)
encoded_data = encoded_data.encode('utf-8')
response = urllib.request.urlopen(url, encoded_data)
This is the exception it is raised after the request:
raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 401: Unauthorized
One way of authenticating successfully is by using urllib2
and python2
and passing user info in the URL but I want to do it the right way and not like this: http://admin:admin@localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost,service=Health
.