【问题标题】:googleapiclient.errors.HttpError: HttpError 404googleapiclient.errors.HttpError: HttpError 404
【发布时间】:2021-02-05 11:47:37
【问题描述】:

我已经导入了谷歌库

from googleapiclient.errors import HttpError, Error

这是我的代码

response = service.users().get(userKey=email).execute()

user_id=(response['id'])
try:
    if user_id:
        return True
# except googleapiclient.errors.HttpError as e:
except googleapiclient.errors.HttpError as e:
    print(e)

但它仍然没有捕捉到那个异常。

这是错误

googleapiclient.errors.HttpError: <HttpError 404 when requesting https://admin.googleapis.com/admin/directory/v1/users/cccc%404domain`enter code here`.com?alt=json returned "Resource Not Found: userKey". Details: "Resource Not Found: userKey">

我的代码的目的是检查该电子邮件是否已经存在。 如果电子邮件存在,则会打印电子邮件地址,但如果电子邮件不存在,则会在上方显示此错误消息

【问题讨论】:

    标签: python gmail google-api-client google-directory-api


    【解决方案1】:

    我今天也遇到了同样的问题。

    发现问题是在您当前拥有 .execute 的地方引发错误。

    试试这个库

    from googleapiclient import errors
    

    尝试将execute放入while或if语句中

    response = service.users().get(userKey=email)
    
    if response is not None:
        try:
            r = response.execute()
            user_email = r.get('primaryEmail', [])
            print(user_email)
    
        except errors.HttpError:
            print('Not found')
    

    【讨论】:

      猜你喜欢
      • 2018-08-26
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 2019-08-13
      相关资源
      最近更新 更多