Create a gist now

Instantly share code, notes, and snippets.

@c7h /gist:5526802
Last active Dec 17, 2015

What would you like to do?
authenticates user at HI-PLAN
import requests
def authenticate(username, password, fh="fhin"):
"""
'authenticates' user at hiplan-app
@return: session id
@raise LoginFailedException: if login fails
"""
url = "https://www2.primuss.de/stpl/login.php"
values = {
"user": username,
"pwd": password,
"mode": "login",
"fh": fh,
"lang": "de",
"submitLogin":"Anmelden"
}
response = requests.post(url, data=values, params={"FH": fh, "Lang": "de"})
the_page = response.text
session_id_list = re.findall(r"(?:name\=\"Session\".{1,5}value\=\")([A-Za-z0-9]+)(?:\")", the_page)
if len(session_id_list) <= 0:
raise LoginFailedException("could not login")
return session_id_list[0]
class LoginFailedException(Exception):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment