title: Facebook Messenger Bot Python Send Image
body: <p>I'm trying to send an image with a facebook bot. I can send text fine, but whenever I try to send a message I get an error: <strong>TypeError: open file 'plot.jpg', mode 'rb' at 0x7f34a2fe8b70 is not JSON serializable</strong>. I'm using flask and heroku for the bot if that makes a difference. </p>
  
  <p>This is my code: </p>
  
  <pre><code>def send_message(recipient_id, message_text):
  
      log("sending message to {recipient}: {text}".format(recipient=recipient_id, text=message_text))
  
      params = {
          "access_token": os.environ["PAGE_ACCESS_TOKEN"]
      }
      headers = {
          "Content-Type": "application/json"
      }
      log(os.getcwd())
      data = json.dumps({
          'recipient': {
              'id': recipient_id
          },
          'message': {
              'attachment': {
                  'type': 'image',
                  'payload': {}
              }
          },
          'filedata': (os.path.basename('plot.jpg'), open('plot.jpg', 'rb'))
      })
      r = requests.post("https://graph.facebook.com/v2.6/me/messages", params=params, headers=headers, data=data)
      if r.status_code != 200:
          log(r.status_code)
          log(r.text)
  </code></pre>