title: python requests upload file
body: <p>I'm visiting a website and I want to upload a file.</p>
  
  <p>I wrote the code in python:</p>
  
  <pre><code>import requests
  
  url = 'http://example.com'
  files = {'file': open('1.jpg', 'rb')}
  r = requests.post(url, files=files)
  print(r.content)
  </code></pre>
  
  <p>But it seems no file has been uploaded, and the page is the same as the initial one.</p>
  
  <p>I wonder how I could upload a file.</p>
  
  <p>The source code of that page:</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;meta charset="utf-8" /&gt;&lt;/head&gt;
  
  &lt;body&gt;
  &lt;br&gt;&lt;br&gt;
  Upload&lt;br&gt;&lt;br&gt;
  &lt;form action="upload.php" method="post"
  enctype="multipart/form-data"&gt;
  &lt;label for="file"&gt;Filename:&lt;/label&gt;
  &lt;input type="hidden" name="dir" value="/uploads/" /&gt;
  &lt;input type="file" name="file" id="file" /&gt; 
  &lt;br /&gt;
  &lt;input type="submit" name="submit" value="Submit" /&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>