title: Login and upload file using Python 'requests'
body: <p>I need to login and upload a file . The problem I am facing is, login page is different from uploading page. If I have to do it manually, I'll login (<code>login.php</code>) to the site and then navigate to the upload page (<code>uploader.php</code>) to upload the file. This what I have written:</p>
  
  <pre><code>import requests
  
  url1='http://www.abc.com/login.php'
  r = requests.post(url1, auth=('uname', 'pword'))
  print r.status_code //msg:'200'
  
  payload = {'upload':open('./tmp.txt')}
  url2='http://www.abc.com/uploader.php'
  r = requests.post(url2, data=payload)
  print r.text //msg: "you must first login to upload the file"
  </code></pre>
  
  <p>My code is obviously not working as expected. Login part is working correctly but not uploading part.
  Please how can I accomplish my goal.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>To give more insight into my question, I am giving <code>login.php</code> and <code>uploader.php</code> file details:</p>
  
  <p><strong>login.php</strong></p>
  
  <pre><code>&lt;form method="POST" action="login.php" class="login"&gt;
  &lt;input type="text" name="username"&gt;&lt;/input&gt;
  &lt;input type="password" name="password"&gt;&lt;/input&gt;        
  &lt;input type="submit" value="Login"&gt;&lt;/input&gt;
  </code></pre>
  
  <p><strong>uploader.php</strong></p>
  
  <pre><code>&lt;form action='uploader.php' method='POST' id='form' class='upload' enctype="multipart/form-data" &gt;
  &lt;input type='file' name='upload' id='file'&gt;&lt;/input&gt;
  &lt;input type='button' value='Analyze' name='button' onclick='javascript: checkuploadform(false)'&gt;
  </code></pre>