I've been trying to write a program which gets my school timetable which is locked behind a login screen, however when I run my python script I am greeted by:
Sorry, we are unable to complete this request
An error occured while submitting the form:
Invalid Request Origin
This is the code I've written so far:
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)
And this is the html from the login page:
<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>Forgotten your password?</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>
How exactly would I be able to solve this error, or would there be any other more viable solutions? Thank you.
This error Invalid Request Origin means that your origin does not match what is restricted by the server. You could try adding the Origin: header specifying your timetable_url, but it is likely that the page can only be called by another page on the server.
Related
I'm brand new to coding and am following the Udemy Zero to Mastery course. I'm currently having trouble getting my HTML5 to process a function I've made in Python. I want to return my function, submit_form, when I click on 'send message'. Here's the HTML5:
<section id="three">
<h2>Get In Touch</h2>
<p>This is the contact section.</p>
<div class="row">
<div class="col-8 col-12-small">
<form method="post" action="index.html">
<div class="row gtr-uniform gtr-50">
<div class="col-6 col-12-xsmall"><input type="text" name="name" id="name"
placeholder="Name" /></div>
<div class="col-6 col-12-xsmall"><input type="email" name="email" id="email"
placeholder="Email" /></div>
<div class="col-12"><textarea name="message" id="message" placeholder="Message"
rows="4"></textarea></div>
</div>
</form>
<ul class="actions">
<!-- <button type="submit" class="btn btn-default btn-lg">Send Message</button> -->
<li><input type="button" value="Send Message" /></li>
</form>
</ul>
</div>
And here is my python function:
#app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
return 'form submitted!'
I'm having a lot of trouble understanding how to make the send message button return my function. Any help is much appreciated, thank you!
So I've seen that there are a couple of similar questions but none of them worked for me. This is the login page that I'm trying to log in to:
https://cas.lu.se/cas/login?service=http%3A%2F%2Fwww.ceq.lth.se%2Frapporter%2F%3Flasar_lp%3Dalla%26program%3Dsamtliga%26kurskod%3DEDAA45%26sort%3Dkurskod
The form has the following html:
<div class="box fl-panel" id="login">
<form action="/cas/login;jsessionid=C32FA3678B0093A4DB474BFD56858B6C?service=http%3A%2F%2Fwww.ceq.lth.se%2Frapporter%2F%3Flasar_lp%3Dalla%26program%3Dsamtliga%26kurskod%3DEDAA45%26sort%3Dkurskod" class="fm-v clearfix" id="fm1" method="post">
Please enter your userid without "#lu.se" at the end.<br/><br/>
<div class="row fl-controls-left">
<label class="fl-label" for="username"><span class="accesskey">U</span>sername:</label>
<input accesskey="u" autocomplete="false" class="required" id="username" name="username" onblur="makeLowercase();" size="25" tabindex="1" type="text" value=""/>
</div>
<div class="row fl-controls-left">
<label class="fl-label" for="password"><span class="accesskey">P</span>assword:</label>
<input accesskey="p" autocomplete="off" class="required" id="password" name="password" size="25" tabindex="2" type="password" value=""/>
</div>
<div class="row btn-row">
<input name="lt" type="hidden" value="LT-61720-irxrtm4JCzVNIJ2pkpidljNGOw5KYX"/>
<input name="execution" type="hidden" value="e1s1"/>
<input name="_eventId" type="hidden" value="submit"/>
<input accesskey="l" class="btn-submit" name="submit" tabindex="4" type="submit" value="LOGIN"/>
<input accesskey="c" class="btn-reset" name="reset" tabindex="5" type="reset" value="CLEAR"/>
</div>
</form>
</div>
So far I've tried using urllib in the following way:
from urllib import request, parse
auth = parse.urlencode({"username": "??",
"password": "??",
"lt": "LT-61720-irxrtm4JCzVNIJ2pkpidljNGOw5KYX",
"execution": "e1s1",
"_eventId": "submit",
"submit": "LOGIN", })
auth = auth.encode("ascii")
req = request.Request(url,
with request.urlopen(url) as f:
res = f.read()
The problem is that the only thing I get back is the html for the original page itself, and not the page that it is supposed to load after authentication. I'm also not sure what the action attribute contains in the form tag...
Can't figure out why Google won't let me log into my account. I put my email inside a variable called my_mail then search for it in the html but the results came back false.
I am using the requests & beautifulsoup modules to do so.
What I have:
from bs4 import BeautifulSoup
import requests
form_data={'Email': 'ExampleEmail#gmail.com', 'Passwd': 'Password'}
post = "https://accounts.google.com/signin/challenge/sl/password"
my_mail = 'ExampleEmail#gmail.com'
with requests.Session() as s:
soup = BeautifulSoup(s.get("https://accounts.google.com/ServiceLogin?elo=1").text, "html.parser")
for inp in soup.select("#gaia_loginform input[name]"):
if inp["name"] not in form_data:
form_data[inp["name"]] = inp["value"]
s.post(post, form_data)
print(my_mail in "https://mail.google.com/mail/u/0/#inbox")
Form info:
<form novalidate="" method="post" action="https://accounts.google.com/signin/challenge/sl/password" id="gaia_loginform">
<input name="Page" type="hidden" value="PasswordSeparationSignIn">
<input type="hidden" name="GALX" value="c90FYb-yd6E">
<input type="hidden" name="gxf" value="AFoagUVMILWKQvqlGV0i8sJG83jiQlrWzg:1475424777331">
<input id="profile-information" name="ProfileInformation" type="hidden" value="">
<input type="hidden" id="_utf8" name="_utf8" value="☃">
<input type="hidden" name="bgresponse" id="bgresponse" value="js_disabled">
<input type="hidden" id="pstMsg" name="pstMsg" value="1">
<input type="hidden" id="dnConn" name="dnConn" value="">
<input type="hidden" id="checkConnection" name="checkConnection" value="youtube:230:1">
<input type="hidden" id="checkedDomains" name="checkedDomains" value="youtube">
<div class="form-panel first valid" id="gaia_firstform">
<div class="slide-out ">
<div class="input-wrapper focused">
<div id="identifier-shown">
<div>
<label class="hidden-label" for="Email">
Enter your email</label>
<input id="Email" type="email" value="" spellcheck="false" name="Email" placeholder="Enter your email" autofocus="">
<input id="Passwd-hidden" type="password" spellcheck="false" class="hidden">
</div>
</div>
<span role="alert" class="error-msg" id="errormsg_0_Email"></span>
</div>
<div style="display: none" id="identifier-captcha">
<input type="hidden" name="identifiertoken" id="identifier-token" value="">
<input type="hidden" name="identifiertoken_audio" id="identifier-token-audio">
<div class="audio-box">
<div id="playIdentifierAudio"></div>
</div>
<div id="captcha-box" class="captcha-box">
<div id="captcha-img" class="captcha-img" data-alt-text="Visual verification">
</div>
<span class="captcha-msg">
Letters are not case-sensitive
</span>
</div>
<label for="identifier-captcha-input" class="hidden-label"></label>
<input type="text" id="identifier-captcha-input" name="identifier-captcha-input" class="captcha" placeholder="Enter the letters above" title="Type the characters you see or numbers you hear">
</div>
<input id="next" name="signIn" class="rc-button rc-button-submit" type="submit" value="Next">
<a class="need-help" href="https://accounts.google.com/signin/usernamerecovery?hl=en">
Find my account
</a>
</div>
</div>
<a href="https://accounts.google.com/ServiceLogin" tabindex="-1">
<img id="back-arrow" class="back-arrow " aria-label="Back" tabindex="0" alt="Back" src="https://www.gstatic.com/images/icons/material/system/1x/arrow_back_grey600_24dp.png">
</a>
<div class="form-panel second">
<div class="slide-in hide-form">
<div>
<p id="profile-name"></p>
<span id="email-display"></span>
</div>
<div>
<div id="password-shown"></div>
</div>
<input id="signIn" name="signIn" class="rc-button rc-button-submit" type="submit" value="Sign in">
<label class="remember">
<input id="PersistentCookie" name="PersistentCookie" type="checkbox" value="yes" checked="checked">
<span>
Stay signed in
</span>
<div class="bubble-wrap" role="tooltip">
<div class="bubble-pointer"></div>
<div class="bubble">
For your convenience, keep this checked. On shared devices, additional precautions are recommended.
Learn more
</div>
</div>
</label>
<input type="hidden" name="rmShown" value="1">
<a id="link-forgot-passwd" class="need-help" href="https://accounts.google.com/signin/recovery?hl=en">
Forgot password?
</a>
</div>
</div>
<span id="inge" style="display: none" role="alert" class="error-msg">
Sorry, Google doesn't recognize that email. Create an account using that address?
</span>
<span id="timeoutError" style="display: none" role="alert" class="error-msg">
Something went wrong. Check your connection and try again.
</span>
</form>
I don't plan on using Google's API. I don't want to be restricted.
Why is the login failing? What could I do to fix it?
I need to login to scrap some information that requires a login.
Pyhton 3.4.2
I have written the code below, which is supposed to upload an image to a site called Roblox using Requests.
import requests
s = requests.session()
login_data = dict(username='USERNAMEHERE', password='PASSWORDHERE')
s.post('https://www.roblox.com/newlogin', data=login_data)
upload_data = dict(name="PythonUpload")
r = s.post('http://www.roblox.com/build/upload', files={'file': open('PythonDecalUploadTest.jpg', 'rb')}, data=upload_data)
print(r) #This returns a 500 error
Here is the form that this is posting to.
<form action="/build/upload" enctype="multipart/form-data" id="upload-form" method="post">
<input name="__RequestVerificationToken" type="hidden" value="H_69BCzd4bdyJ7EXalAOvaa-zeZZOvtQR-E9YHnCpmH9HVZKxHGrSVjAciLInCibyD8k432ZRzqX8d0MPPfCv-vOfAM1">
<input id="assetTypeId" name="assetTypeId" type="hidden" value="13">
<input id="isOggUploadEnabled" name="isOggUploadEnabled" type="hidden" value="True">
<input id="groupId" name="groupId" type="hidden" value="">
<input id="onVerificationPage" name="onVerificationPage" type="hidden" value="False">
<div id="container">
<div class="form-row">
<label for="file">Find your image:</label>
<input id="file" type="file" name="file" tabindex="1">
<span id="file-error" class="error"></span>
</div>
<div class="form-row">
<label for="name">Decal Name:</label>
<input id="name" type="text" class="text-box text-box-medium" name="name" maxlength="50" tabindex="2">
<span id="name-error" class="error"></span>
</div>
<div class="form-row submit-buttons">
<a id="upload-button" class="btn-medium btn-primary btn-level-element " tabindex="3">Upload</a>
<span id="loading-container">
<img src="http://images.rbxcdn.com/ec4e85b0c4396cf753a06fade0a8d8af.gif">
</span>
</div>
</div>
</form>
I'm not sure what the request verification token is, so I just changed a few letters/numbers just in case.
So why is this returning a 500 error? Why isn't it uploading my image?
I am running an html page on apache2:
http://localhost/test.html
I want to send the username to a python script check.py, How can I do that?
html:
<div id="wrapper">
<form name="login-form" class="login-form" action="check.py" method="post" onsubmit="validate();return false;">
<div class="header">
<h1>Login Form</h1>
<span>Fill out the form below to login to my super awesome imaginary control panel.</span>
</div>
<div class="content">
<input id="Uname" name="username" type="text" class="input username" placeholder="Username" />
<div class="user-icon"></div>
<input id="Pname"name="password" type="password" class="input password" placeholder="Password" />
<div class="pass-icon"></div>
</div>
<div class="footer">
<input type="submit" name="submit" value="Login" class="button"/>
<input type="submit" name="submit" value="Register" class="register" />
</div>
</form>
</div>
<div class="gradient"></div>
</body>
</html>
Well you are running a static page, their is no way you can pass the page data to python file this way.
What you need is to learn server side programming.
In python Django and Flask are the popular framework for server side programming.
Below is a question related to flask. that will suits your need
Sending data from HTML form to a Python script in Flask