title: uploading a file to imgur via python
body: <p>I'm having trouble uploading an image to Imgur using the python requests module and the Imgur API.</p>
  
  <p>My code is the following:</p>
  
  <pre><code>import base64
  import json
  import requests
  
  from base64 import b64encode
  
  client_id = 'my-client-id'
  
  headers = {"Authorization": "Client-ID my-client-id"}
  
  api_key = 'my-api-key'
  
  url = "http://api.imgur.com/3/upload.json"
  
  j1 = requests.post(
      url, 
      headers = headers,
      data = {
          'key': api_key, 
          'image': b64encode(open('1.jpg', 'rb').read()),
          'type': 'base64',
          'name': '1.jpg',
          'title': 'Picture no. 1'
      }
  )
  </code></pre>
  
  <p>I usually get a 400 response error. I'm not sure if myu client_id is wrong, or if my request is wrong (I have very little experience on url requesting), or if I'm using the Imgur API wrong. </p>
  
  <p>I'd also like to get the url of the image once I have submitted this. I'm not sure if the API has a command for that, or if the python.requests module has a trick that can let me GET the data I just posted(POST).</p>
  
  <p>A very similar question was answered here, and the code actually worked!: <a href="https://stackoverflow.com/questions/11437444/python-requests-trouble-sending-a-file-to-imgur">Trouble sending a file to Imgur</a></p>
  
  <p>However when I used my client_id, insted of the application ID that was used in the code, it returned a 400 error, as well as when I changed</p>
  
  <p>from:
      url = "<a href="https://api.imgur.com/2/upload.json" rel="nofollow noreferrer">http://api.imgur.com/2/upload.json</a>"
  to:
      url = "<a href="https://api.imgur.com/3/upload.json" rel="nofollow noreferrer">http://api.imgur.com/3/upload.json</a>"</p>