title: Python Requests: how to GET and POST a picture without saving to drive?
body: <p>The API I'm working on has a method to send images by POSTing to <code>/api/pictures/</code> with the picture file in the request.</p>
  
  <p>I want to automate some sample images with Python's requests library, but I'm not exactly sure how to do it. I have a list of URLs that point to images.</p>
  
  <pre><code>rv = requests.get('http://api.randomuser.me')
  resp = rv.json()
  picture_href = resp['results'][0]['user']['picture']['thumbnail']
  rv = requests.get(picture_href)
  resp = rv.content
  rv = requests.post(prefix + '/api/pictures/', data = resp)
  </code></pre>
  
  <p><code>rv.content</code> returns bytecode. I get a 400 Bad Request from the server but no error message. I believe I'm either 'getting' the picture wrong when I do <code>rv.content</code> or sending it wrong with <code>data = resp</code>. Am I on the right track? How do I send files?</p>
  
  <p><strong>--Edit--</strong></p>
  
  <p>I changed the last line to </p>
  
  <pre><code>rv = requests.post('myapp.com' + '/api/pictures/', files = {'file': resp})
  </code></pre>
  
  <p>Server-side code (Flask):</p>
  
  <pre><code>file = request.files['file'] 
  if file and allowed_file(file.filename):
      ...
  else:
      abort(400, message = 'Picture must exist and be either png, jpg, or jpeg')
  </code></pre>
  
  <p>Server aborts with status code 400 and the message above. I also tried reading <code>resp</code> with BytesIO, didn't help.</p>