diff --git a/langchain/document_loaders/googledrive.py b/langchain/document_loaders/googledrive.py index e8ef11de1c..cf3d44eed1 100644 --- a/langchain/document_loaders/googledrive.py +++ b/langchain/document_loaders/googledrive.py @@ -142,6 +142,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel): from io import BytesIO from googleapiclient.discovery import build + from googleapiclient.errors import HttpError from googleapiclient.http import MediaIoBaseDownload creds = self._load_credentials() @@ -151,8 +152,16 @@ class GoogleDriveLoader(BaseLoader, BaseModel): fh = BytesIO() downloader = MediaIoBaseDownload(fh, request) done = False - while done is False: - status, done = downloader.next_chunk() + try: + while done is False: + status, done = downloader.next_chunk() + + except HttpError as e: + if e.resp.status == 404: + print("File not found: {}".format(id)) + else: + print("An error occurred: {}".format(e)) + text = fh.getvalue().decode("utf-8") metadata = {"source": f"https://docs.google.com/document/d/{id}/edit"} return Document(page_content=text, metadata=metadata)