Skip to content

The agent engineering platform.

community[patch]: added latin-1 decoder to gmail search tool (#18116)

Sanjaypranav V Mb9a495e56ebb
diff --git a/libs/community/langchain_community/tools/gmail/search.py b/libs/community/langchain_community/tools/gmail/search.py
index bcd16e0931..8c49db5e86 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")