If there's an easier, cleaner way of doing this, please let me know. I'm trying to replicate this call:
curl -s -u user -k "https://10.10.10.10:8001/h/data/ps4"
This call requires a password. What I've done to try to mimic this is:
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
top_level_url = "https://10.10.10.10:8001"
password_mgr.add_password(None, top_level_url, 'user', 'pass')
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(urllib2.HTTPHandler, handler)
request = urllib2.Request('https://10.10.10.10:8001/h/data/ps4')
print urllib2.urlopen(request).read()
However, this doesn't seem to work, as I get:
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized
The output from the curl command returns a list of strings (e.g., ["a","b","c"]) -- Ideally I'd like to store this into a python list somehow, but I can't get past the first bit.
What am I doing wrong?