Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

python - googleapiclient.errors.HttpError: HttpError 404

I have imported google library

from googleapiclient.errors import HttpError, Error

and this is my code

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)

but it is still not catching that exception.

Here is the error

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">

purpose of my code is to check if that email already exists. If email exists it prints the email address but if email dose not exist it gives this error message above

question from:https://stackoverflow.com/questions/66062716/googleapiclient-errors-httperror-httperror-404

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the exact same problem today.

Found the issue to be that the error is raising where you have .execute currently.

Try this library

from googleapiclient import errors

Try putting execute into a while or if statement

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')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...