I've seen a few problems like this but they have a different answer than I was hoping so here I am.
I am planning to send mail details such that the client's mail app opens with the message sent via the form.
Thing is though, I've seen it being doable with PHP but I am running a Flask app.
So is there a way to do it using Python?
This is my form code:
<form id="contactForm" name="sentMessage" novalidate="novalidate" action="mailto:mail#gmail.com?subject=feedback&body=message">
<div class="control-group">
<div class="form-group floating-label-form-group controls mb-0 pb-2"><label>Name</label><input class="form-control" type="text" id="name" required="" placeholder="Name"><small class="form-text text-danger help-block"></small></div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls mb-0 pb-2"><label>Email Address</label><input class="form-control" type="email" id="email" required="" placeholder="Email Address"><small class="form-text text-danger help-block"></small></div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls mb-5 pb-2"><textarea class="form-control" id="message" required="" placeholder="Message" rows="5"></textarea><small class="form-text text-danger help-block"></small></div>
</div>
<div id="success"></div>
<div class="form-group"><button class="btn btn-primary btn-xl" id="sendMessageButton" type="submit">Send</button></div>
</form>
What I am looking to do is send a subject and content that is present in the textarea element as the body.
I managed to solve it myself with a workaround using redirect and request and it worked.
#app.route('/test',methods=['POST'])
def test():
mess=request.form['textarea']
return redirect('mailto:test#email.com?body='+str(mess))
In the form what I changed was
<form id="contactForm" name="sentMessage" novalidate="novalidate" action="{{url_for('test'}}" method="POST">
Related
I am trying to get report from id-pwd required site. This site is showing 2 different login sites randomly (I do not know why, but I am guessing they do not like retrieving data by bot).
Login HTML 1:
<div class="login-modal-content">
<form accept-charset="UTF-8" action="/mp/login" class="signin-page-form" name="sign-in-form" method="post" novalidate="novalidate">
<div class="field email-field fade-label">
<label class="text" for="email">Email Address</label>
<input autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="autofocus" class="text" id="email" name="email" size="30" spellcheck="false" type="email" value="">
</div>
<div class="message-box-error-wrapper">
<div class="message-box-error"></div>
</div>
<div class="field password-field fade-label">
<label class="text" for="password">Password</label>
<input class="text" id="password" name="password" size="30" autocomplete="off" type="password" value="">
<div class="login-forgot-password-wrapper">
Forgot Password
</div>
</div>
<div style="clear: both"></div>
<div id="captcha" class="g-recaptcha submit-button"></div>
<div class="submit-button full-length-submit-button">
<button id="sign-in-button" name="sign-in-button" type="submit" class="btn btn-blue track-event">
<span class="button-text">Sign In</span>
</button>
</div>
<div class="footer">
Don’t have a ---- account?
<span class="signup-today">
Sign up
</span>
</div>
</form>
</div>
Login HTML 2.
<main class="layout-base__body">
<h1 data-test-heading="">Sign in</h1>
<p data-test-subheading="">
New to Square? <market-link href="/signup?country_code=us&lang_code=en" hydrated="">Sign up</market-link>
</p>
<form data-test-form="" name="sign-in-form">
<market-field data-test-email-field="" hydrated="">
<market-input-text data-test-email-input="" name="email" input-id="email" autocomplete="username" type="email" value="" hydrated="" class="">
<label for="email">Email address</label>
</market-input-text>
<!---->
</market-field>
<market-field data-test-password-field="" hydrated="">
<market-input-password data-test-password-input="" name="password" type="password" hydrated="">
<label for="password">Password</label>
</market-input-password>
<!---->
</market-field>
<p>
<div>
<market-link data-test-forgot-password="" id="login-standard-forgot-password-link" href="#" hydrated="">
Forgot password?
</market-link>
</div>
</p>
<!---->
<div>
<market-button data-test-submit="" id="login-standard-submit" name="sign-in-button" rank="primary" role="button" type="button" variant="regular" size="medium" hydrated="">
Sign in
</market-button>
</div>
</form>
</main>
Here is my partial code for login.
def find_single_name(browser, timeout, el_name):
try:
WebDriverWait(browser, timeout).until(
EC.presence_of_element_located(
(By.NAME, el_name)
)
)
element = browser.find_element(By.NAME, el_name)
return element
except TimeoutException:
print(f"Could not find element ID of {el_name}")
return None
###########
login_id = find_single_name(browser=browser, timeout=60, el_name='email')
login_id.click()
login_id.clear()
login_id.send_keys(id)
time.sleep(1)
login_pwd = find_single_name(
browser=browser, timeout=60, el_name='password')
login_pwd.click()
login_pwd.clear()
login_pwd.send_keys(pwd)
time.sleep(1)
login_btn = find_single_name(
browser=browser, timeout=60, el_name='sign-in-button')
login_btn.click()
time.sleep(timeout)
When I happened to get login HTML 1 page, no problem to sign in and download all the reports I need, but same code is not working on login HTML 2. browser closed in no time on login 2 HTML.
I am struggling with this problem for weeks and gave up to solve this issue. Please advise me. I am praying not to deal with login 2 HTML whenever scraping that site...
I am trying to update the password if the user has forgotten while Login-in. But continuously it is giving the same error given below.
Bad Request: The browser (or proxy) sent a request that this server could not understand.
app.py
#app.route('/NewPassword', methods=['POST', 'GET'])
def NewPassword():
if request.method == 'POST':
OldEmail = request.form['NewPswdInputEmail']
OldPhone = request.form['NewPswdInputPhoneNo']
NewPaswd = request.form['NewPaswdInputPassword']
cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("UPDATE USERS SET Paswd='" + NewPaswd + "' WHERE Email ='" + OldEmail + "' OR Phone ='" + OldPhone + "'")
cur.connection.commit()
return "Password Updated"
return render_template('NewPassword.html')
NewPassword.html
<form action="/NewPassword" method="post" oninput='NewPaswdConPassword.setCustomValidity(NewPaswdConPassword.value != NewPaswdInputPassword.value ? "Password does not match." : "")'>
<div class="form-group">
<label for="customRadio">Select Option to Change Password Between Email & Phone No.</label>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="customRadioInline1" name="customRadioInline" value="Email" class="custom-control-input" checked>
<label class="custom-control-label" for="customRadioInline1">Email Id</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="customRadioInline2" name="customRadioInline" value="Phone" class="custom-control-input">
<label class="custom-control-label" for="customRadioInline2">Phone No.</label>
</div>
</div>
<div class="form-group" id="EmailShowHide">
<label for="NewPswdInputEmail">Email Address</label>
<input type="email" class="form-control" name="loginInputEmail" id="NewPswdInputEmail" aria-describedby="emailHelp" placeholder="Email address">
<small id="loginemailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group" id="PhoneShowHide" style="display: none">
<label for="NewPswdInputPhoneNo">Phone Number</label>
<input type="tel" id="NewPswdInputPhoneNo" name="NewPswdInputPhoneNo" class="form-control" pattern="[0-9]{4}[0-9]{2}[0-9]{4}" placeholder="Phone number">
<small id="NewPswdPhoneHelpInline" class="text-muted">Enter Valid Number</small>
</div>
<div class="form-group">
<div class="tool">
<label for="NewPaswdInputPassword">New Password</label>
<div class="input-group" id="NewPaswdShowHide">
<input type="password" class="form-control" name="NewPaswdInputPassword" id="NewPaswdInputPassword" pattern="^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,20}$" placeholder="New password" required>
<div class="input-group-append">
<a class="btn btn-primary">
<i class="bi bi-eye-slash" aria-hidden="true"></i>
</a>
</div>
</div>
<span class="tooltext">Password Must be Alphanumeric with atleast an UpperCase & LowerCase Characters</span>
<small id="NewPaswdHelpInline" class="text-muted">Must be 8-20 characters long.</small>
</div>
</div>
<div class="form-group">
<label for="NewPaswdInputConPassword">Confirm New Password</label>
<input type="password" class="form-control" name="NewPaswdConPassword" id="NewPaswdInputConPassword" placeholder="Confirm new password" required>
</div>
<button type="submit" name="Login" id="NewPaswdSubmit" class="btn btn-primary">Submit</button>
</form>
I am trying to do is, if my database "USERS" has Email or Phone no. then Paswd will get updated with the new password which is input by the user
Please tell me what I am doing wrong.
I assume you are using Flask. Is your application running in debug mode?
Running the application in debug mode can help identify where the issue is.
The issue is with the email HTML form input. When you submit a form, the data is sent as key=value pairs, in this case you are using Flask so it is a python dictionary. So in the /NewPassword route, when you request request.form['NewPswdInputEmail'], you are grabbing a value in that dictionary submitted from the form with 'NewPswdInputEmail' as a key.
In the form input the key is the name attribute.
That's why you get the KeyError because the name in the email input form has name="loginInputEmail" instead of name="NewPswdInputEmail"
All you need to do is rename loginInputEmail attribute in the email input field to NewPswdInputEmail.
I've been trying to use the request library in order to send information to a web server. However, I have no clue what data to send to the server in order to log in. (This is my first time using requests and I was wondering if someone could help explain this to me)
Edit: I'm trying to make it submit a username and password to the site.
My code:
import requests
Sdata = {'username':'testingemail#gmail.com','password':'testing123','login':'submit'}
r = requests.post(url = 'https://gmchosting.com/billing/clientarea.php',data=Sdata)
html = r.text
print(html)
The Part of the website I want the file to communicate with:
<input type="hidden" name="token" value="003cc13dfa662dd183f098c2a2afc81331da0ba3" />
<div class="form-group">
<label for="inputEmail">Email Address</label>
<input type="email" name="username" class="form-control" id="inputEmail" placeholder="Enter email" autofocus>
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="rememberme" /> Remember Me
</label>
</div>
<div align="center">
<input id="login" type="submit" class="btn btn-primary" value="Login" /> Forgot Password?
</div>
</form>
</div>
You can use parameters in the url, like this:
https://google.com?myparameter=true
And you can get them using JS.
So, you can use:
import webbrowser
webbrowser.open('https://example.com?myparam=hello&hello=yeah')
And in the JS:
const params = new URLSearchParams(window.location.search);
const myparam = decodeURIComponent(urlp.get('myparam'));
alert(myparam)
I am trying to put a button inside an email input in a Django form.
This is the code with the button next to the email input:
<div class="container" id="notifyEmailFormContainer">
<form action="{% url "landing:notify_email_add" %}" method="post" id="notifyEmailForm">
{% csrf_token %}
<div class="form-group row">
<div class="col-sm-10 input-group" id="emailInput">
<div class="input-group-addon" id="comingSoonEmailIcon"><i class="fa fa-envelope fa fa-2x" aria-hidden="true"></i></div>
<input class="form-control" type="email" name="email" placeholder="Your email...." maxlength="255" required id="id_email"/>
</div>
<div class="col-sm-2">
<button type="button" class="btn btn-block btn-primary" onclick="addNotifyEmail()" id="submitNotifyEmail">Notify Me</button>
</div>
</div>
</form>
</div>
I have a tried a couple answers in similar questions but it seems I can't get it to work.
I'm using the requests module with python 3.3 and am trying to post data. This is the data I'm trying to post. I've already parsed the values from the html:
<form action="/checkoutnow/2" autocomplete="off" class="proceed" id="loginForm" method="post" name="login_form" novalidate="novalidate">
<input id="loginForm" name="execution" type="hidden" value="e21s1"> <input name="token" type="hidden" value="EC-2MJ027776Y1687721"> <input id="incontext" name="incontext" type="hidden" value="0"> <input id="eventID" name="_eventId_submit" type="hidden">
<div class="" id="loginFields">
<div class="inputField emailField confidential">
<label for="email">Email</label> <input autocomplete="off" data-validate-email="true" id="email" name="email" type="email" value="">
<div class="tip tipHint">
<div class="tipArrow tipArrowFront tipHintArrowFront"></div>
<div class="tipArrow tipArrowBack tipHintArrowBack"></div>
<ul class="tipText tipHintText">
<li>Did you mean <a class="emailLink" href=""></a>?
</li>
</ul>
</div>
</div>
<div class="inputField passwordField confidential">
<label for="password">Password</label> <input autocomplete="off" id="password" maxlength="22" name="password" type="password" value="">
<div class="toolTip tip guestTooltip">
<div class="tipArrow tipArrowFront tipErrorArrowFront"></div>
<div class="tipArrow tipArrowBack tipErrorArrowBack"></div>
<div class="tipText tipErrorText">
Trouble logging in? You can try again, or <a class='submit' href='/checkoutnow/2?execution=e21s1&_eventId_guest' id='guestTooltipLink'>check out as a guest</a>
</div>
</div>
</div>
</div>
<div class="buttons varA">
<input class="btn full continue" name="_eventId_submit" type="submit" value="Log in to PayPal">
<div class="forgotPassword secondary" id="forgotPasswordSection">
<a href='/us/merchantpaymentweb?cmd=_account-recovery&from=PayPal' id='forgotPassword' target='_blank'>Forgot your password?</a>
</div>
<hr class="sep">
<a class="btn btn-secondary submit" href="/checkoutnow/2?execution=e21s1&_eventId_guest&token=EC-2MJ027776Y1687721" id="checkoutAsAGuestBtn">Pay with Debit or Credit Card</a>
</div>
</form>
And here is my code to get past this. I am using a session btw.
payload6 = {'loginFields': {'password': paypalpass, 'email': useremail}, 'token': token, 'execution': execution, 'incontext': incontext, '_eventId_submit': ''}
r = session.post(urlnow, data=payload6)
I believe my problem is with the 'loginFields' as after I post, the values are still empty.
Your POST data shouldn't have any nested dicts. password and email should be top-level keys like token and execution are, and not nested under loginFields like they are now. (I assume loginFields is in your payload now because of that <div id="loginFields">, but wrappers like that shouldn't have any effect on how the POST data is structured.)
It turns out javascript was generating more variables. Thanks for the help though.