title: How to upload photos/pictures to Zoom API using Python (multipart/form-data) with JWT?
body: <p>I have been racking my brains trying to get this to work with Python. I see you can do this using Curl and JavaScript, but I prefer not to leave Python. Reading the documents (though, they are pretty bare), it says you must simply format the data in the headers as <code>multipart/form-data</code> and send the file as a binary.</p>
  <pre><code>import requests
  
  userid = 'myuserid@place.com'
  url = 'https://api.zoom.us/v2/users/{0}/picture'.format(userid)
  jwt_token = '&lt;supersecretkey&gt;'
  filepath = '/Users/me/Pictures/myprofilepic.jpg'
  
  headers = {
    'Content-Type': 'multipart/form-data',
    'Authorization': 'Bearer {0}'.format(jwt_token)
  }
  
  files = [
    ('pic_file', open('&lt;filepath&gt;','rb'))
  ]
  
  response = requests.request('POST', url, headers=headers, files=files)
  
  print(response.status_code)
  </code></pre>
  <p>This example, however, does not work. I keep getting 500 errors. I opened a support case with Zoom and received this exact same code to run. I tried to tackle this myself by formatting and setting my boundaries.</p>
  <pre><code>import requests
  import binascii
  import os
  import base64
  
  jwt_token = '&lt;supersecretkey&gt;'
  filepath = '/Users/me/Pictures/myprofilepic.jpg'
  
  def encode_image_base64(filename):
      with open(filename,'rb') as file:
          data_read = file.read()
          data = base64.b64encode(data_read)
      return data
  
  def base64_encode_multipart_formdata(name,filename,content_type):
      base64image = encode_image_base64(filename)
      boundary = binascii.hexlify(os.urandom(16)).decode('ascii')
      body = '--{0}\r\nContent-Disposition: form-data; name=&quot;{1}&quot;; filename=&quot;{2}&quot;\r\nContent-Type: {3}\r\n\r\n{4}\r\n--{0}--'.format(boundary,name,filename,content_type,base64image)
      content_type = &quot;multipart/form-data; boundary={}&quot;.format(boundary)
      return( body, content_type)
  
  def main():
      name = 'pic_file'
      content_type = 'image/jpeg'
      body , ct = base64_encode_multipart_formdata(name,filepath,content_type)
      headers = {
          'Content-Type': '{}'.format(ct),
          'Authorization': 'Bearer {}'.format(jwt_token)
      }
      response = requests.post(url, headers=headers, data=body)
      print(response.status_code)
  </code></pre>
  <p>This does not work either.</p>