- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用服务帐户在我的 gmail 框中列出邮件,但是在调用此 API 时出现以下错误 service.users().messages().list(userId='me').execute()
HttpError Traceback (most recent call last)
<ipython-input-44-da1dc3cccc81> in <module>
27
28 apiservice = build('gmail', 'v1', credentials=service_cred)
---> 29 response = apiservice.users().messages().list(userId='me').execute()
~/opt/anaconda3/lib/python3.7/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
128 elif positional_parameters_enforcement == POSITIONAL_WARNING:
129 logger.warning(message)
--> 130 return wrapped(*args, **kwargs)
131 return positional_wrapper
132
~/opt/anaconda3/lib/python3.7/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
849 callback(resp)
850 if resp.status >= 300:
--> 851 raise HttpError(resp, content, uri=self.uri)
852 return self.postproc(resp, content)
853
HttpError: <HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/messages?alt=json returned "Precondition check failed.">
代码:
scopes = [
"https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.labels",
"https://www.googleapis.com/auth/gmail.metadata",
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
]
service_cred = service_account.Credentials.from_service_account_info(
credentials, scopes=scopes)
service = build('gmail', 'v1', credentials=service_cred)
response = service.users().messages().list(userId='me').execute()
最佳答案
当我尝试从我的个人电子邮件中列出电子邮件时,我也遇到了这个问题。启用 Gmail API 时,Google 仪表板为我设置了服务帐户凭据,因此我认为这就是我应该使用的。
为了消除 400 错误,我必须添加:
delegated_credentials = credentials.with_subject('my-email@gmail.com')
见
https://developers.google.com/identity/protocols/oauth2/service-account#authorizingrequests .
关于google-api - HttpError 400 Precondition check failed during users().messages().list Gmail API call using service account,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62846906/
我收到“HTTP 错误 500:内部服务器错误”响应,但我仍想读取错误 HTML 中的数据。 使用 Python 2.6,我通常使用以下方法获取页面: import urllib2 url = "ht
我的 API 提供商在 response.body 中发送错误消息作为 ReadableStream为纯文本,我需要让管理员在休息时将这些消息显示给最终用户。 我打算这样做: import HttpE
我正在尝试从Youtube数据API获取视频数据,但是在经过一定数量的请求调用(大约900次)后,我遇到了(500)后端错误,我也试图等待15分钟的间隔,持续4到5次,但仍然抛出同样的错误 错误: b
刚开始学Python,就遇到了这个问题。真正解析来自亚马逊的价格并将其打印到控制台。 这是我的代码: import requests, bs4 def getAmazonPrice(productUr
刚开始学Python,就遇到了这个问题。真正解析来自亚马逊的价格并将其打印到控制台。 这是我的代码: import requests, bs4 def getAmazonPrice(productUr
测试一些使用 urllib2 的代码, 我想养一个 HTTPError以确保它得到正确处理。 HTTPError 有一个构造函数: def __init__(self, url, code, msg,
如果是 404,我想捕获带有额外信息的 urllib2.HTTPError: try: data = urlopen(url) except HTTPError, e: # Python 2
我在 IIS 7 上本地运行的 Asp.Net 4 中有一个 Web 应用程序。 我需要为 IIS 的默认页面显示一个自定义页面 (404) 和一个 500。 在 Web.Config 中使用这个 h
我在为 cherrypy.HTTPError 提供自定义响应处理时遇到问题.我希望在响应正文中显示的唯一内容是 JSON 编码的 dict(这是 REST API)。源代码似乎表明HTTPError.
我在 web.config 中有这个: 但是 IIS 仍然显示内置的错误页面。 有什么想法吗? 最佳答案 这就是我使用它的方式,它对我有用,除了 subStatusCode
如何在 Angular 服务中模拟 HTTP 错误响应?我经常需要处理不同的 HTTP 错误代码,有时我需要实现解决方案,但后端还没有准备好。如何从后端模拟错误? 示例代码 public getD
在我的Google帐户(不是主要帐户)上,我创建了OAuth凭据,可以访问CMS及其 channel 。使用此凭据,我可以从YouTube Analytics(分析)API中获取数据,因此这里没有问题
我已将以下内容添加到配置文件中。 ... 但是,我似乎仍然得到带有黄色背景和堆栈跟踪的默认页面。我试过在 system.web 中注释掉用于错误处理和添加/删除
当我尝试运行 conda update numpy 时出现以下错误(也在运行 conda update conda 时) Fetching package metadata ............C
我正在尝试找出一种使用 ASP.NET WebApi 返回具有非 200 返回代码的自定义负载的方法。基本上我想拥有 {"status":{"code":"40001", "message": "Fi
我在实现 MyFaces 2.0 时使用 JSF我有 2 个 jsf 页面 login.xhtml 和 register.xhtml。 登录.xhtml: System CollD
如何返回 HttpError(自己的、格式漂亮的前端错误消息)然后使用方便的 IHttpActionResult? public IHttpActionResult Delete(Guid id) {
我正在用 python 尝试“Hello world” import webapp2 class MainHandler(webapp2.RequestHandler): def get(
如何获取 中设置的 errorMode 属性的值? web.config 中的元素? 我正在尝试在 ASP.NET Web 应用程序中实现一些“ self 诊断”。当应用程序启动时,它会运行 web
我正在尝试用 ruby 编写一个简单的网络抓取代码。它一直工作到第 29 个 url,然后我收到此错误消息: C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:346:i
我是一名优秀的程序员,十分优秀!