• <i id='whmLZ'><tr id='whmLZ'><dt id='whmLZ'><q id='whmLZ'><span id='whmLZ'><b id='whmLZ'><form id='whmLZ'><ins id='whmLZ'></ins><ul id='whmLZ'></ul><sub id='whmLZ'></sub></form><legend id='whmLZ'></legend><bdo id='whmLZ'><pre id='whmLZ'><center id='whmLZ'></center></pre></bdo></b><th id='whmLZ'></th></span></q></dt></tr></i><div id='whmLZ'><tfoot id='whmLZ'></tfoot><dl id='whmLZ'><fieldset id='whmLZ'></fieldset></dl></div>
  • <small id='whmLZ'></small><noframes id='whmLZ'>

    <legend id='whmLZ'><style id='whmLZ'><dir id='whmLZ'><q id='whmLZ'></q></dir></style></legend>

        <bdo id='whmLZ'></bdo><ul id='whmLZ'></ul>
    1. <tfoot id='whmLZ'></tfoot>

      1. Python Gmail API'不是 JSON 可序列化的'

        Python Gmail API #39;not JSON serializable#39;(Python Gmail API不是 JSON 可序列化的)

        <legend id='ofkuL'><style id='ofkuL'><dir id='ofkuL'><q id='ofkuL'></q></dir></style></legend>

          <bdo id='ofkuL'></bdo><ul id='ofkuL'></ul>

          <small id='ofkuL'></small><noframes id='ofkuL'>

            <tfoot id='ofkuL'></tfoot>
                    <tbody id='ofkuL'></tbody>

                1. <i id='ofkuL'><tr id='ofkuL'><dt id='ofkuL'><q id='ofkuL'><span id='ofkuL'><b id='ofkuL'><form id='ofkuL'><ins id='ofkuL'></ins><ul id='ofkuL'></ul><sub id='ofkuL'></sub></form><legend id='ofkuL'></legend><bdo id='ofkuL'><pre id='ofkuL'><center id='ofkuL'></center></pre></bdo></b><th id='ofkuL'></th></span></q></dt></tr></i><div id='ofkuL'><tfoot id='ofkuL'></tfoot><dl id='ofkuL'><fieldset id='ofkuL'></fieldset></dl></div>
                  本文介绍了Python Gmail API'不是 JSON 可序列化的'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I want to send an Email through Python using the Gmail API. Everythingshould be fine, but I still get the error "An error occurred: b'Q29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PSJ1cy1hc2NpaSIKTUlNRS..." Here is my code:

                  import base64
                  import httplib2
                  
                  from email.mime.text import MIMEText
                  
                  from apiclient.discovery import build
                  from oauth2client.client import flow_from_clientsecrets
                  from oauth2client.file import Storage
                  from oauth2client.tools import run_flow
                  
                  
                  # Path to the client_secret.json file downloaded from the Developer Console
                  CLIENT_SECRET_FILE = 'client_secret.json'
                  
                  # Check https://developers.google.com/gmail/api/auth/scopes for all available scopes
                  OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.compose'
                  
                  # Location of the credentials storage file
                  STORAGE = Storage('gmail.storage')
                  
                  # Start the OAuth flow to retrieve credentials
                  flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
                  http = httplib2.Http()
                  
                  # Try to retrieve credentials from storage or run the flow to generate them
                  credentials = STORAGE.get()
                  if credentials is None or credentials.invalid:
                    credentials = run_flow(flow, STORAGE, http=http)
                  
                  # Authorize the httplib2.Http object with our credentials
                  http = credentials.authorize(http)
                  
                  # Build the Gmail service from discovery
                  gmail_service = build('gmail', 'v1', http=http)
                  
                  # create a message to send
                  message = MIMEText("Message")
                  message['to'] = "myemail@gmail.com"
                  message['from'] = "python.api123@gmail.com"
                  message['subject'] = "Subject"
                  body = {'raw': base64.b64encode(message.as_bytes())}
                  
                  # send it
                  try:
                    message = (gmail_service.users().messages().send(userId="me",     body=body).execute())
                    print('Message Id: %s' % message['id'])
                    print(message)
                  except Exception as error:
                    print('An error occurred: %s' % error)
                  

                  解决方案

                  I had this same issue, I assume you are using Python3 I found this on another post and the suggestion was to do the following:

                  raw = base64.urlsafe_b64encode(message.as_bytes())
                  raw = raw.decode()
                  body = {'raw': raw}
                  

                  Check out: https://github.com/google/google-api-python-client/issues/93

                  这篇关于Python Gmail API'不是 JSON 可序列化的'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  • <bdo id='eAko7'></bdo><ul id='eAko7'></ul>
                    <legend id='eAko7'><style id='eAko7'><dir id='eAko7'><q id='eAko7'></q></dir></style></legend>
                  • <i id='eAko7'><tr id='eAko7'><dt id='eAko7'><q id='eAko7'><span id='eAko7'><b id='eAko7'><form id='eAko7'><ins id='eAko7'></ins><ul id='eAko7'></ul><sub id='eAko7'></sub></form><legend id='eAko7'></legend><bdo id='eAko7'><pre id='eAko7'><center id='eAko7'></center></pre></bdo></b><th id='eAko7'></th></span></q></dt></tr></i><div id='eAko7'><tfoot id='eAko7'></tfoot><dl id='eAko7'><fieldset id='eAko7'></fieldset></dl></div>

                      • <small id='eAko7'></small><noframes id='eAko7'>

                      • <tfoot id='eAko7'></tfoot>

                            <tbody id='eAko7'></tbody>