0

I am trying to login into a website through python but the form fields have no name just the ID's

<ul>
                    <li id="unLi" class="unLi"><input class="text" id="userName" type="text" maxlength="15" /></li>
                    <li class="blank"></li>
                    <li id="pwLi" class="pwLi"><input class="text" id="pcPassword" type="password" maxlength="15"/></li>
</ul>

I tried the following code

import requests

params = {'userName':'sahil','pcPassword':'mypassword'}
r = requests.post("http://192.168.1.2/",data=params)
r.status_code
print(r.text)

on submit the form calls a javascript function PCSubWin() which goes something like this

function PCSubWin()
{
    if((httpAutErrorArray[0] == 2) || (httpAutErrorArray[0] == 3))
    {
        if(true == CheckUserPswInvalid())
        {
            var username = $("userName").value;             
            var password = $("pcPassword").value;   
            if(httpAutErrorArray[1] == 1)
            {
                password = hex_md5($("pcPassword").value);  
            }           
            var auth = "Basic "+ Base64Encoding(username + ":" + password);
            document.cookie = "Authorization="+escape(auth)+";path=/";
            //location.href ="/userRpm/LoginRpm.htm?Save=Save";
            $("loginForm").submit();
            return true;
        }
        else
        {
            $("note").innerHTML = "NOTE:";
            $("tip").innerHTML = "Username and password can contain between 1 - 15 characters and may not include spaces."; 
        }
    }
    return false;

now I am not very good at javascript but i assume this peice of code $("userName").value is getting the values entered by the user, my question is how can I call to this function when submitting my credentials? my code btw prints out the same code for the login page not the user home page.

1 Answer 1

1

The site you're requesting is using Basic HTTP Authentication so you can just call:

requests.get('http://192.168.1.2/userRpm/LoginRpm.htm', auth=('sahil', 'mypassword'))

to access the protected resource.

Sign up to request clarification or add additional context in comments.

4 Comments

could you tell me how would I verify my login? for ex I can grab the homepage url from the browser, is there any way to verify that I can access it? @moritzg
@Sahil By looking at the HTTP Status code. If the login is unsuccesful the server should return a 401 or a 403. If all goes well you get a 200.
even with wrong credentials its giving me a 200 response @moritzg
@Sahil Because http://192.168.1.2/ is the login page, which you can access without logging in. You need to request the protected url. I guess that's http://192.168.1.2/userRpm/LoginRpm.htm for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.