我一直在尝试编写一个程序,该程序将我的学校时间表锁定在登录屏幕后,但是当我运行python脚本时,我受到欢迎:
Sorry, we are unable to complete this request
An error occured while submitting the form:
Invalid Request Origin
这是我到目前为止编写的代码:
import requests
login_url = 'https://WEBSITE/login?page=%2Fhomepage'
timetable_url = 'https://WEBSITE/timetable'
payload = {
'username': 'USERNAME',
'password': 'PASSWORD'
}
with requests.Session() as session:
post = session.post(login_url, data=payload, verify = True)
r = session.get(timetable_url)
print (post.text)
这是登录页面中的html:
<div id="content">
<form id="login" method="post" action="/login?page=%2Flogin%2F">
<input type="hidden" name="page" value="/login/" />
<div class="row collapse">
<div class="small-12 column">
<div class="logo">
<img src="/images/logo.php?logo=skin_logo_login&size=normal" alt="Schoolbox" />
</div>
</div>
<div class="small-12 column">
<p id="error-msg" class="alert-box alert"></p>
</div>
<div class="small-12 column">
<input type="text" name="username" id="username" placeholder="Username" />
<input type="password" name="password" id="password" placeholder="Password" />
</div>
</div>
<div class="row collapse">
<div class="small-12 column">
<p><a href="/forgotten-password.php">Forgotten your password?</a></p>
</div>
<div class="small-12 column">
<input id="rememberme" type="checkbox" name="rememberme" value="1" />
<label for="rememberme">Remember me</label>
</div>
<div class="small-12 column login-links">
<input type="submit" name="Submit" value="Login" alt="Login" />
</div>
</div>
</form>
</div>
我将如何准确地解决此错误,或者还有其他更可行的解决方案?谢谢。
此错误Invalid Request Origin
表示您的来源与服务器限制的来源不匹配。您可以尝试添加指定Origin:
的timetable_url
标头,但该页面很可能只能由服务器上的另一个页面调用。