title: API Gmail : renturns error "Object of type bytes is not JSON serializable"
body: <p>the code available at : <a href="https://developers.google.com/gmail/api/guides/sending#python" rel="nofollow noreferrer">https://developers.google.com/gmail/api/guides/sending#python</a>
  asks to create the content of the e-mail encoded as base64url string, and offers the following code :</p>
  <pre><code>def create_message(sender, to, subject, message_text):
      message = MIMEText(message_text)
      message['to'] = to
      message['from'] = sender
      message['subject'] = subject
      return {'raw': base64.urlsafe_b64encode(message.as_string())}
  </code></pre>
  <p>So, when sending :</p>
  <pre><code>def send_message(service, user_id, message):
      try:
          message = (service.users().messages().send(userId=user_id, body=message).execute())
  </code></pre>
  <p>the returned message :
  &quot;Object of type bytes is not JSON serializable&quot;</p>
  <p>Thanks for your help</p>
  <p>bob2fox</p>