I have a python application logs in to a remote host via basic HTTP authentication.
Authentication is as follows:
def make_authenticated_request(host, username, password):
url = host
r = requests.get(url, auth=(username, password))
r.raise_for_status()
return r
test = Looter.make_authenticated_request("http://" + host + "/status/status_deviceinfo.htm", user, password)
This error is printed:
401 Client Error: Unauthorized for url
Strange thing is that this doesn't always happen. It randomly fails/succeeds, for the same host with the same credentials.
Login is however correct, and works flawlessly in my browser. I'm no python ninja. Any clues ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…