-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intermittent Failure in Fetching Emails Using googleapiclient.discovery in Gmail API #2448
Comments
Hi @ohmayr , did you had a chance to check the issue? It is causing some real pain |
Hi @shikharvaish28, thanks for reporting this and sharing the reproduction code. I see that you've also shared some logs for the requested requested URL. Can you share the error / response that you're getting for a failed request? |
Hi @ohmayr, since I use the python library I don't have the response. Instead, I did add some more logging and here is what it got:
def get_otp_from_email(tries=0) -> str:
service = get_gmail_service()
try:
results = service.users().messages().list(
userId='me',
maxResults=1,
labelIds=['INBOX'],
q="from:[email protected] is:unread subject:Transaction OTP"
).execute()
message = results.get('messages', [])[0]
if not message:
logger.warning('[get_otp] No messages from CDSL found.')
else:
msg = service.users().messages().get(userId='me', id=message['id']).execute()
email_data = msg['payload']['headers']
for values in email_data:
name = values["name"]
if name == "From":
from_name = values["value"]
match_opt = re.search('(\d{6})', str(msg['snippet']))
return match_opt.group()
except Exception as exp:
logger.warning("[get_otp] No messages from CDSL found to read", exp)
if tries >= 5:
logger.error("[get_otp] No email from edis even after %s tries", tries)
exit()
# If email is not received, wait for 15 seconds and try again
while tries < 5:
time.sleep(15)
get_otp_from_email(tries=tries + 1) Please suggest if I need to add something to get the response |
@shikharvaish28 I ran the provided script with my own query parameters and i'm able to successfully get the I can't say for sure why it isn't working in your case since you mentioned that it only happens sometimes. Try tinkering with the query parameters and see if it works? Would help if you have a concrete example to reproduce this. |
@ohmayr so that's precisely the problem - the message fetch fails sometimes, but not always(however it does happen atleast thrice a week, and the code runs only once a day). This happens across two tenants with different accounts. The code runs simultaneously on both instances, but usually, only one fails while the other succeeds. Can you help me add debug logs to capture the exception/response so that I can share the same when the message fetch fails? |
We are experiencing intermittent failures when attempting to fetch emails using the googleapiclient.discovery library with the Gmail API. Despite the presence of the emails in the inbox that match the query criteria, the API sometimes fails to retrieve them.
Steps to reproduce
googleapiclient.discovery
library to fetch emails from the Gmail inbox.Version of libraries
Code example
Here is the code I have been using for a year, and it fails sometime
Stack trace
Here is the truncated log of the day it failed
Thanks!
The text was updated successfully, but these errors were encountered: