I'd like to write a Python script to auto login to my broadband usage meter account. I've never done a POST submit before and I'm having some trouble with it.
import urllib.request, urllib.parse, urllib.error
import socket
try:
details = urllib.parse.urlencode({ 'IDToken1': 'USERNAME', 'IDToken2': 'PASSWORD' })
url = urllib.request.Request('https://login1.telecom.co.nz/distauth/UI/Login?realm=XtraUsers&goto=https%3A%2F%2Fwww.telecom.co.nz%3A443%2Fjetstreamum%2FxtraSum%3Flink%3Drdt', details)
url.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13")
responseData = urllib.request.urlopen(url).read().decode('utf8', 'ignore')
responseFail = False
except urllib.error.HTTPError as e:
responseData = e.read().decode('utf8', 'ignore')
responseFail = False
except urllib.error.URLError:
responseFail = True
except socket.error:
responseFail = True
except socket.timeout:
responseFail = True
except UnicodeEncodeError:
print("[x] Encoding Error")
responseFail = True
print(responseData)
From the HTML I derived that IDToken1
is the username id and IDToken2
is the password id.
Here is my problem:
When I enter the correct username and password, the login page loads, but:
When I enter the incorrect username or password, I get a page that says:
This server has encountered an internal error which prevents it from fulfilling your request. The most likely cause is a misconfiguration. Please ask the administrator to look for messages in the server's error log.