title: Python 3 Requests - How to make a post request, fill in forms and submit
body: <p>In a website with this code from flask:</p>
  
  <pre><code>from flask import Flask, request
  
  app = Flask(__name__)
  
  
  @app.route('/upload', methods=["POST", "GET"])
  def upload():
      return """
          &lt;html&gt;
            &lt;body&gt;
              &lt;h1&gt;Guess what! I am a title!&lt;/h1&gt;
                &lt;form action="/run" method="POST" name="upload"&gt;
                  &lt;input type="password" name="password"&gt;
                  &lt;input type="file" name="file" /&gt;
                &lt;/form&gt;
            &lt;/body&gt;
          &lt;/html&gt;"""
  
  
  @app.route('/run', methods=["POST"])
  def download_file():
      if request.form['password'] == 'hey':
          request.files['file'].save('/home/james/site.txt')
          return "File uploaded successfully!"
      else:
          return "Wrong password"
  </code></pre>
  
  <p>How can I run a proper post request and get the output of <code>/run</code>?
  So far I've tried:</p>
  
  <pre><code>upload = {'password': 'whatever',
            'file': open(my_files_location, 'rb')}
  r = requests.post('http://jamesk.pythonanywhere.com/upload', data=upload)
  </code></pre>
  
  <p>But the website neither has run the form nor did it return what I wanted. This is what I get when I run <code>r.content</code>:</p>
  
  <pre><code>b'\n        &lt;html&gt;\n          &lt;body&gt;\n            &lt;h1&gt;Guess what! I am a title!&lt;/h1&gt;\n              &lt;form action="/run" method="POST" name="upload"&gt;\n                &lt;input type="password" name="password"&gt;\n                &lt;input type="file" name="file" /&gt;\n              &lt;/form&gt;\n          &lt;/body&gt;\n        &lt;/html&gt;'
  </code></pre>
  
  <p>When I expected <code>b'Wrong password'</code></p>