def Login(username, password): path = "/" url = Request.MakeURL(Host, path, {}, TLS) (resp_header, resp_body) = Request.Request(url) session_cookie = "" for item in resp_header: if item[0] == "Set-Cookie" and "session" in item[1]: session_cookie = item[1].split(";")[0] #print(session_cookie) csrf_nonce = "" match = re.findall("csrf_nonce = \"([0-9a-f]+?)\"", resp_body.decode("utf-8")) if len(match) > 0: csrf_nonce = match[0] #print(csrf_nonce) path = "/login" url = Request.MakeURL(Host, path, {}, TLS) header = { "Content-Type": "application/x-www-form-urlencoded", "Cookie": session_cookie, } query = { "name": username, "password": password, "nonce": csrf_nonce, } body = Request.MakeBody(query, header) (resp_header, resp_body) = Request.Request(url, body, header) for item in resp_header: if item[0] == "Set-Cookie" and "session" in item[1]: session_cookie = item[1].split(";")[0] #print(session_cookie) HEADER["cookie"] = session_cookie return