我已经导入了google library
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">
我的代码的目的是检查电子邮件是否已经存在。如果email存在,则打印email地址;如果email不存在,则给出
上面的错误信息我今天也遇到了同样的问题。
发现问题是,错误正在上升,你有。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')