Log in to website behind CloudFlare using Python Requests

2.6k views Asked by At

Trying to post a login to a website but cant seem to get it working.

Here is the returned error:

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare-nginx</center>
</body>

Here is form that I'm trying to post the requests to login to:

<form name="loginform" id="loginform" method="post" action="login.php" onsubmit="return formVal();">
<table cellpadding="2" cellspacing="1" border="0" align="center">
    <tr valign="top">
        <td align="right">Username&nbsp;</td>
        <td align="left"><input type="text" name="username" id="username" class="inputtext" autofocus="autofocus" /></td>
    </tr>
    <tr valign="top">
        <td align="right">Password&nbsp;</td>
        <td align="left"><input type="password" name="password" id="password" class="inputtext" /></td>
    </tr>
    <tr valign="top">
        <td colspan="2" align="right"><input type="checkbox" name="keeplogged" value="1" />Keep me logged in</td>
    </tr>
            <tr>
                <td colspan="2" align="right"><input type="submit" name="login" value="Log In!" class="submit" /></td>
    </tr>
</table>
<br /><br />
Lost your password? <a href="login.php?act=recover">Recover it here!</a>

Pls help!

1

There are 1 answers

1
Vikas Ojha On BEST ANSWER

Try getting the page first and then post, like this -

with cfscrape.create_scraper() as s:
    p = s.get(login_url)
    p = s.post(login_url, data=payload)
    print p.content