From b9a495e56ebb20b27a684e6e69370b7c73590732 Mon Sep 17 00:00:00 2001 From: Sanjaypranav V M Date: Thu, 29 Feb 2024 00:58:29 +0530 Subject: [PATCH] community[patch]: added latin-1 decoder to gmail search tool (#18116) some mails from flipkart , amazon are encoded with other plain text format so to handle UnicodeDecode error , added exception and latin decoder Thank you for contributing to LangChain! @hwchase17 --- libs/community/langchain_community/tools/gmail/search.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/tools/gmail/search.py b/libs/community/langchain_community/tools/gmail/search.py index bcd16e09311..8c49db5e866 100644 --- a/libs/community/langchain_community/tools/gmail/search.py +++ b/libs/community/langchain_community/tools/gmail/search.py @@ -98,7 +98,12 @@ class GmailSearch(GmailBaseTool): ctype = part.get_content_type() cdispo = str(part.get("Content-Disposition")) if ctype == "text/plain" and "attachment" not in cdispo: - message_body = part.get_payload(decode=True).decode("utf-8") + try: + message_body = part.get_payload(decode=True).decode("utf-8") + except UnicodeDecodeError: + message_body = part.get_payload(decode=True).decode( + "latin-1" + ) break else: message_body = email_msg.get_payload(decode=True).decode("utf-8")