username = 'foo'
password = 'bar'
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, MY_APP_PATH, username, password)
authhandler = urllib.request.HTTPBasicAuthHandler(passman)
opener = urllib.request.build_opener(authhandler)
urllib.request.install_opener(opener)
params = {'param1': param1, 'param2': param2, 'param3': param3}
xmlResults = urllib.request.urlopen(MY_APP_PATH, urllib.parse.urlencode(params)).read()
results = MyResponseParser.parse(xmlResults)
How do I add basic authentication to a Python REST request?