我已经导入了google库
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">
我的代码的目的是检查该电子邮件是否已经存在。如果电子邮件存在,它会打印电子邮件地址,但如果电子邮件不存在,则会显示上面的错误消息
发布于 2021-02-06 21:56:43
今天我也遇到了同样的问题。
发现问题是错误出现在您当前使用.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')
https://stackoverflow.com/questions/66062716
复制相似问题