I'm new in Python. I'm trying to log in to the site, but it doesn’t work out (remain unauthorized). What am I doing wrong?
import requests
with requests.Session() as c:
url = 'https://kartoteka.ru'
LOGIN = 'somelogin'
PWD = 'secretpassword'
PROMO = ""
c.get(url)
loginData = dict(login=LOGIN, pwd=PWD, promo=PROMO)
c.post(url, data=loginData, headers = {"Referer": "https://kartoteka.ru"})
page=c.get(url)
print(page.content)
The first this is it looks like you've missed this input in the login form:
<input type="checkbox" id="scratchcard_checkbox" name="scratchcard" value="scratchcard" style="top: 2px; position: relative;margin-right: 4px;">
So you should add a scratchcard option to your login data.
Edit: Here's the whole form:
<form action="" method="post" class="form-horizontal">
<div class="auth-ep-select" id="auth-cert-list-area"></div>
<div class="form-group no-margin-bottom">
<label class="control-label col-sm-12 col-xs-12 col-md-12 auth-login-label">Промо-код</label>
<div class="col-sm-12 col-xs-12 col-md-12 auth-text-field">
<span class="fa fa-lock user-auth-icon"></span>
<input id="auth_promo" class="form-control in-auth-control" value="" type="text" name="promo" placeholder="Промо-код"/>
</div>
</div>
<div class="form-group">
<div class="col-xs-12 auth-btn-block text-center" style="margin-top:15px">
<button type="button" data-loading-text="Войти" class="btn btn-md btn-info auth-btn js-dlg-auth-btn">Войти</button>
</div>
</div>
<div class="form-group text-center">
<a class="auth-registration-link" onsubmit="yaCounter23391682.reachGoal('registraciya'); return true;" href="/reguser/" style="color:#ffffff;">Регистрация </a>
<span>/</span>
<a class="success auth-buy-ep" href="/uc/" role="button" onsubmit="yaCounter23391682.reachGoal('kypit_ep'); return true;" title="Купить ЭП"> Купить ЭП</a>
</div>
</form>
Why do you bother GETting the url at the start? I don't think that's necessary.
How to you know you remain unauthorised? You're not saving the Request object from when you POST with the login data, so how do you know it returns an error code.
BTW, it's much quicker to declare a literal dictionary that create one like that, and you don't need it within the session.
import requests
ROOT_URL = 'https://kartoteka.ru'
USERNAME, PASSWORD = 'login', 'pass'
PROMO = ''=
with requests.Session() as c:
login_data = {'login': USERNAME, 'pwd': PASSWORD,
'promo': PROMO, 'scratchcard': false}
login_request = c.post(ROOT_URL,
data=login_data,
headers={"Referer": "https://kartoteka.ru"})
login_request.raise_for_status()
print(c.get(ROOT_URL).content)
I don't know if that will fix anything, but it's probably a start.
Related
I see the following HTML code when I import it from website throught selenium. The ids I want to access are hidden inside the body and I am not able to access them using Selenium Python.
</head>
<!--[if IE 9]>
<body style="display:none" class="ie9">
<![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body style="display:none">
<!--<![endif]-->
This is the code I see in the website through inspect option.
<form action="" method="post" class="form login col-sm-6 col-sm-offset-3" data-stage="DataStore1">
<fieldset class="row">
<div class="form-group">
<label class="sr-only separator" for="idToken1">
<span>Benutzername</span>
</label>
<input type="text" id="idToken1" name="callback_0" value="" data-validator="required" required="" data-validator-event="keyup" class="form-control input-lg" placeholder="Benutzername" autofocus="">
</div>
<div class="form-group">
<label for="idToken2" class="aria-label sr-only separator">
<span>Passwort</span>
</label>
<input type="password" id="idToken2" name="callback_1" class="form-control input-lg" placeholder="Passwort" value="" data-validator="required" required="" data-validator-event="keyup">
</div>
<div class="remember-forgot clearfix">
<div class="checkbox pull-left">
<label for="remember"><input type="checkbox" name="loginRemember" id="remember"> Remember my username</label>
</div>
</div>
<div class="form-group">
<input id="loginButton_0" name="callback_2" type="submit" role="button" index="0" value="Log in" class="btn btn-lg btn-block btn-uppercase btn-primary">
</div>
ch license between the licensee and ForgeRock AS.
</fieldset>
</form>
I am using Chrome webdriver.
from selenium import webdriver
driver = webdriver.Chrome(r'C:\WebDriver\bin\chromedriver.exe')
driver.get('https://app.int.eu.acdc.fdc.swarm.audi/goldenalgo#dario/data-distribution')
a = driver.find_element_by_id("idToken1")
a.send_keys(username)
print(w.value_of_css_property("display"))
print(driver.page_source)
time.sleep(5)
driver.find_element_by_id('idToken2').send_keys(password)
driver.find_element_by_id('loginButton_0').click()
driver.close()
driver.find_element_by_id("idToken1") this doesn't work and returns the error "unable to find element with css selector error in selenium".
Thanks in advance
I have adjust controller name with route and send form that post method but it didnt work, i send it from modal
I have add {{ method_field('patch') }} but it still didnt work
This is from view :
<form action="{{route('edit kode', 'test')}}" method="post">
{{ method_field('patch') }}
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="material-icons">clear</i>
</button>
<h5 class="modal-title">Edit Data</h5>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="bmd-label-floating">Kode</label>
<input type="hidden" class="form-control" id="modalidkode">
<input type="text" class="form-control" id="modalkode" readonly>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label class="bmd-label-floating">Nama Kode</label>
<input type="text" class="form-control" id="modalnamakode" required>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal"
style="margin-right: 10px">Batal
</button>
<button type="submit" class="btn btn-info">Simpan Perubahan</button>
</div>
Controller
public function editCode(Request $request){
dd($request->all());
$edCode="05.01";
return redirect()->back()->withSuccess($edCode. " changed");
}
Route
Route::post('/pengaturan/edit', 'AllCodeController#editCode')->name('edit kode');
You're expecting the request to be a POST request in your routes, but your form is submitting a PATCH request (because of the method_field('patch') at the top of your form). Either remove the method_field() call, or change Route::post(...) to Route::patch(...).
You can read more about form method spoofing in the Laravel documentation:
HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method:
<form action="/foo/bar" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
Im try build a form to upload images, but when use csrf this donw work for me and, I was reading that need this code in you form enctype tag:
<form method="post" action="/?_csrf=<%=csrfToken%>">
this work for me but if want save one image only, but if want Edit or Delete, don't work, because use override method ?_method=PUT and return a URl with me CSRF
http://localhost:3030/stories/5bafe7a5abe3a7110c5f386b?_csrf=wkhEeV2x-06M_KPnZRoSTPJ3mUZSnuZ6dl7s
Cannot POST
<form class="col s12" action="/stories/{{storieEdit.id}}?_csrf={{csrfToken}}" enctype="multipart/form-data" method="POST">
<input type="hidden" name="_method" value="PUT">
<div class="row">
<div class="file-field input-field col s12">
<div class="btn">
<span>File</span>
<input type="file" name="fileUpload" onchange="previewFile()">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
<img src="/uploads/{{storieEdit.image}}" alt="Image" style="width: 25rem;">
</div>
</div>
</div>
</form>
any suggestions
Thanksfor read me
For multiple images you need to add to your form enctype atribute like this: enctype="multipart/form-data"
For method override you need to add method type as well as csrfToken to action query string:
action="/stories/{{storieEdit.id}}?_method=PUT&_csrf={{csrfToken}}"
I have similar code and works fine.
Bellow you can find the required changes directly in your code.
<form class="col s12" enctype="multipart/form-data" action="/stories/{{storieEdit.id}}?_method=PUT&_csrf={{csrfToken}}" enctype="multipart/form-data" method="POST">
<input type="hidden" name="_method" value="PUT">
<div class="row">
<div class="file-field input-field col s12">
<div class="btn">
<span>File</span>
<input type="file" name="fileUpload" onchange="previewFile()">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
<img src="/uploads/{{storieEdit.image}}" alt="Image" style="width: 25rem;">
</div>
</div>
</div>
</form>
I want to take the input from the user and check the value of it whether it matches the value exists in firebase database or not.
I want to build a login component which provides the functionality of signUp user and signIn. I know it can be implemented by Auth but I want to use custom data. I was able to perform CRUD operations.enter image description here
This is login.component.ts where I want to implement the function
export class LoginComponent implements OnInit {
adminval: string;
passwordval : string;
newnew : string = 'employeeService.loginData.admin';
loginList : LoginID[];
constructor(private employeeService : EmployeeService, private router : Router) { }
ngOnInit() {
this.employeeService.getLoginData();
var x = this.employeeService.getLoginData();
x.snapshotChanges().subscribe(item =>{
this.loginList = [];
item.forEach(element => {
var y = element.payload.toJSON();
y["$key"] = element.key;
this.loginList.push(y as LoginID);
})
})
}
onEdit(emp : LoginID){
this.employeeService.loginData = Object.assign({}, emp);
}
onLogin(loginForm : NgForm){
if(this.adminval == this.employeeService.loginData.admin){
alert("OK");
}
else
alert("Not OK");
}
}
Here the login.component.html file code
<body style="background-color:#DD3247">
<div class="container" style="padding-top: 10%; padding-bottom: 8.1%;">
<div class="row justify-content-md-center">
<div class="col-md-5 login-box">
<h1 class="text-center login-text-color">Login</h1>
<hr>
<form #loginForm="ngForm">
<input type="hidden" name="$key" #$key="ngModel" [(ngModel)]="employeeService.loginData.$key">
<input type="hidden" name="admin" #admin="ngModel" [(ngModel)]="employeeService.loginData.admin" placeholder="Admin">
<input type="hidden" name="password" #password="ngModel" [(ngModel)]="employeeService.loginData.password" placeholder="Password">
<div class="form-row">
<div class="col-md-12">
<input type="text" class="form-control form-control-lg flat-input" name="adminvalue" #adminvalue="ngModel" [(ngModel)]="adminval" placeholder="Admin" required>
</div>
<div class="col-md-12">
<input type="password" class="form-control form-control-lg flat-input" name="passwordvalue" #passwordvalue="ngModel" [ngModel]="passwordval" placeholder="Password" required>
</div>
<button type="submit" class="btn btn-lg btn-block btn-login" (click)="onLogin(loginForm)">Login</button>
</div>
</form>
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-md-center">
<h6 class="text-center">Employee Register</h6><br>
<table class="table table-sm table-hover">
<tr *ngFor="let login of loginList">
<td>{{login.admin}}</td>
<td>{{login.password}}</td>
<td>
<a class="btn" (click)="onEdit(login)">
<i class="fa fa-pencil-square-o"></i>
</a>
<a class="btn">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>
</table>
</div>
</div>
</body>
Somehow, I was able to do it by matching username value but by the wrong implementation. You can see there are 3 input hidden fields in the HTML file so first I have to click on the edit icon then that will insert the existing data into the hidden fields and then if the input from the adminval matches the one of the admin hidden field then it will show OK otherwise Not Ok.
Hello I need to put searching option and value in the URL. I know it's very basic but I have never implement the search function before ever always used the templates one but this time I need to use it. below is my code please help me.
Right now I am getting this in the link
list/%7Boption%7D/%7Bvalue%7D
but I want this in the link list/Hello/thisishelloworld or this may be list/option?Hello/value?thisishelloworld but I think I can get the second option using Get instead of Post method
AND YA ITS IN LARAVEL 5.2
<center>
<div class="form-group">
<label>Select your option from below</label>
<select class="form-control" id="options" name="options" style="width:100%" type="checkbox">
<option>Hello</option>
<option>World</option>
<option>it's Me</option>
</select>
</div>
<div class="col-md-4" id="value">
<div class="panel panel-warning">
<div class="panel-heading">
Enter your Search below
</div>
<form role="form" action="/list/{option}/{value}" method="post">
{{ csrf_field() }}
<div class="form-group has-success">
<input class="form-control" placeholder="Search" type="text" name="{{ value }}" id="value">
<input type="submit" class="btn btn-primary" name="submit" value="Search">
</div>
</form>
</div>
</div>
</center>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function hide() {
$("#value").hide();
$("#h").hide();
$("#search").hide();
}
function show() {
$("#value").show();
$("#h").show();
$("#search").show();
}
function initHandlers() {
$("#options").change(function() {
show();
});
}
hide();
initHandlers();
</script>
Laravel 5. 2
Step 1:
First you have to create a route.
Routes.php :
Route::get('/list', function(){
// do process
})->name('search');
HTML :
something.blade.php :
{!! Form::open('search', ['route' => 'search', 'method' => 'GET']) !!}
<div class="form-group has-success">
<input class="form-control" placeholder="Search" type="text" name="search" id="value">
<input type="submit" class="btn btn-primary" name="submit" value="Search">
</div>
</form>