Filling HTML password field using Python (Requests)
<p>I have been trying to login to a website (<a href="https://osu.ppy.sh/" rel="nofollow">https://osu.ppy.sh/</a>) using the Requests library in Python (<a href="http://docs.python-requests.org/" rel="nofollow">http://docs.python-requests.org/</a>). The following code seems to fill in the "username" field but not the "password" field:</p>

<pre><code>payload = {
    'username': 'some_username',
    'password': 'some_password'
}

with requests.Session() as s:
    p = s.post('https://osu.ppy.sh/forum/ucp.php?mode=login', data=payload)
    print(p.text)
</code></pre>

<p>The output from running the code above contains the following:</p>

<pre><code>&lt;td valign="top"&gt;&lt;b class="gensmall"&gt;Username:&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input class="post" type="text" name="username" size="25" maxlength="40" value="some_username" tabindex="1"/&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;&lt;b class="gensmall"&gt;Password:&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&lt;input class="post" type="password" name="password" size="25" maxlength="100" tabindex="2"/&gt;
&lt;/td&gt;
</code></pre>

<p>Notice how the username text field shows</p>

<pre><code>value="some_username"
</code></pre>

<p>while the password field does not have a value set.</p>

<p>Shouldn't my code set the values of both the username and password fields?</p>

<p>If so, why isn't it setting the value of the password field as well? Is it because the password field is </p>

<pre><code>type="password"
</code></pre>

<p>and Requests.post() can only set the values of text fields?</p>

<p>Is it because the "username" text field has and empty</p>

<pre><code>value=""
</code></pre>

<p>beforehand but the password field doesn't?</p>

<p>It is filling in the password field and I'm just not seeing it?</p>

<p>Any help is appreciated.</p>

<p>First, it's not because the type of password, the most likely point is that your payload is not completed.</p>

<p>I checked the form data to login <a href="https://osu.ppy.sh" rel="nofollow">https://osu.ppy.sh</a>, it likes this:</p>

<p><a href="http://i.stack.imgur.com/bkzlF.png" rel="nofollow"><img src="http://i.stack.imgur.com/bkzlF.png" alt="enter image description here"></a></p>

<p>You can find that the Form Data contains a few of different fields: redirect, sid, username, password, login. </p>

<p>To login success, you should figure out these fields if they are required, and fill the right values in your payload.</p>

python python-3.x python-requests