I am trying to make a user registration and login for an application I'm working on using the form below.
<html><form method="get" action="login">
Email Address: <input name="email" type="text"><br/>
Password: <input name="password" type="password"><br/>
<input type="submit" value="Submit" />
</form>
</html>
However the user name and password show up in the url, as does the submit button.
http://localhost:8080/login?email=123&password=123&submit=Submit
How do I stop this happening?
They show up in the URL because your form is using the GET method, you should be using POST and processing the values on the server side.
In addition to the POST/GET confusion Shawn points out, you might be interested to look at Cherrypy's built-in authentication tool.
Related
I'm working with django and I want to calculate something depending on what the user put on the selectboxes of my page, but I don't know how to connect that with my python code that calculates everything, please help :(
You can use a html form element like this with method post and action="path_of_your_python_file"
<form name="search" action="calculate.py" method="GET">
Search: <input type="checkbox" name="user_input">
<input type="submit" value="Submit">
</form>
Then in calculate.py
import cgi
form = cgi.FieldStorage()
searchterm = form.getvalue('user_input')
// Do your calculation here
I think that will help
edit I believe the issue is that when opening the website for the first time, you must click a "Our privacy policy has been updated..." Accept button. I'm now looking into how I might go about "clicking" this button using python requests, however the button calls a javascript function so I'm not sure if it's possible to do with just the requests library.
I am attempting to write a script for this website: https://rocket-league.com/
I need to be logged in to perform my tasks, but I'm having trouble logging in.
I feel as though I've accounted for all the correct params. I fetch the csrf_token dynamically using regex. Maybe I need to do something with the cookies, but I'm not sure what?
This is my first attempt at writing a script that interacts with websites so I'm sorry if I'm naive.
I'd be grateful for any insights that aren't just a disguised way of telling me I'm dumb and/or lazy.
Here is my code so far:
import requests;
import re;
payload = {
'csrf_token': '',
'email': 'myemail',
'password': 'mypassword',
'submit': 'Login'
}
url = 'https://rocket-league.com/login'
with requests.Session() as s:
r = s.get(url)
m = re.search("<input type='hidden' name='csrf_token' value='(.+)'", r.text)
if m: payload['csrf_token'] = m.group(1)
else: print("couldnt find csrf_token")
p = s.post('https://rocket-league.com/functions/login.php', data=payload)
print(p.text)
Running this code prints out HTML that still has the login form in it which means I am not being logged in.
When I login from my browser with the developer tools > network open, I get this information for my post request:
Headers:
Request URL: https://rocket-league.com/functions/login.php
Request method: POST
Status code: 302 Found
Version HTTP/2.0
Cookies:
__cfduid: d2c83b2c9ad728195366656a56592f6d71549577451
acceptedPrivacyPolicy: 2.0
euconsent: BObnsHAObnsHAABABAENCF-AAAAkF7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_tphPhA
fantasy_rlcs_id: hA8fga9ghIgaFGA9
PHPSESSID: lrse3tgov95eg574sqga6la9jc
Params:
csrf_token: 3f2588113e8921f52dc3eb78e51246a1
email: myemail
password: mypassword
submit: Login
Here is the actual HTML for the login form:
<form class="rlg-form" method="post" action="/functions/login.php">
<input type="hidden" name="csrf_token" value="3accad82ad0957cab634f805a7e28beb">
<input class="rlg-input" type="email" name="email" placeholder="Email" required="">
<input class="rlg-input" type="password" name="password" placeholder="Password" autocomplete="off" required="">
<fieldset class="rlg-checkbox">
<input type="checkbox" name="rememberme" id="rememberme-login">
<label for="rememberme-login">Remember me?</label>
</fieldset>
<input class="rlg-btn-primary" type="submit" name="submit" value="Login">
</form>
I am trying to fill up a form that has following fields :
old password , new password , verify password
<b><u>Please Enter the Informations</u></b><br>
<form method=post action="chpass.php?action=changepass">
<table border=0>
<tr><td>LAN UserName</td><td></td></tr>
<tr><td>Old password</td><td><input type="password" name="password"></td></tr>
<tr><td>New password</td><td><input type="password" name="password1"></td></tr>
<tr><td>Conform password</td><td><input type="password" name="password2"></td></tr>
tr><td colspan=2 align=center>
<input type=submit name="submit" value="submit">
<form><input type="button" onClick="show();" value="Logout"></form>
Using following piece of code in python:
br.open('url_of_form')
br.select_form(nr=0)
br['password']='abc'
br['password1']='bcdef'
br['password2']='bcdef'
br.submit()
I have used this piece of code before to login to site but this isn't working while trying to change password . The error message says 'ParseError: nested FORMs' .
what am i doing wrong ?
You have two open tags and one close tag "form". Maybe its a problem? Try to use grab
i use this code in python to post something to a form in a web page.
but i dont just want to send some text as an input textbox, i also want to decide if a checkbox in the form is checked or not.
what value do i have to give to the 'checkbox' parameter in the "web_form"?
web_form = [('textbox', text),('checkbox', ?????)]
form_data = urllib.urlencode(web_form)
o = urllib2.build_opener(url)
res = o.open(url, form_data).read()
this is the html of the form:
<form action="?" method="POST" enctype="multipart/form-data">
<textarea name="textbox"></textarea> Checkbox <input type='checkbox' name='cb' > <input type="submit" value="submit" /></div>
</form>
You question is pretty broad since you did not mention with web framework you are using.
Application code could check either for the existence of the checkbox key in the request or check for a particular value...unless you provide further informations: try setting it to something like '1' and see what's happening.
HTML:
<form enctype="multipart/form-data" action="/convert_upl" method="post">
Name: <input type="text" name="file_name">
File: <input type="file" name="subs_file">
<input type="submit" value="Send">
</form>
Python (Google App Engine):
if self.request.get('file_name'):
file_name = self.request.get('file_name')
My problem is that I receive no data from file_name text input. I am aware that the trouble is because of it's existence within the form enctype="multipart/form-data" but I don't know how to solve it - I mean how to receive a file and the string from the input with one click of the submit button.
Thanks in advance.
The uploading example code works fine for me. Have you tried using that code exactly? Does it work for you, or what problems do you see?
As you'll see, that example has a form with the same encoding you're using:
<form action="/sign" enctype="multipart/form-data" method="post">
<div><label>Message:</label></div>
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><label>Avatar:</label></div>
<div><input type="file" name="img"/></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
it's just a bit more careful in the HTML to properly use label tags to display field labels, but that only affect the form's looks when rendered in the browser.
The Python code is also similar to what you show (for the tiny susbset that you do show):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get("content")
avatar = self.request.get("img")
greeting.avatar = db.Blob(avatar)
greeting.put()
self.redirect('/')
and of course the /sign URL is directed to the class whose do_post method we've just shown.
So, if this code works and yours doesn't, where is the difference? Not in the part you've shown us, so it must be in some parts you haven't shown... can you reproduce the part about this example code from Google working just fine?
You are using the POST method to send the data but then are trying to get it with the GET method.
instead of
self.request.get('file_name')
do something like
self.request.post('file_name')