Skip to content

Commit

Permalink
fix linting errors.
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Tripathi <rauhl.psit.ec@gmail.com>
  • Loading branch information
Rahul Tripathi committed Apr 4, 2024
1 parent 44f106a commit 89b8fe8
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions libs/community/langchain_google_community/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class GoogleDriveLoader(BaseLoader, BaseModel):
load_auth: bool = False
"""Whether to load authorization identities."""

def _get_identity_metadata_from_id(self, id: str)-> List[str]:
def _get_identity_metadata_from_id(self, id: str) -> List[str]:
"""Fetch the list of people having access to ID file."""
try:
from googleapiclient.discovery import build # type: ignore[import]
import googleapiclient.errors # type: ignore[import]
import googleapiclient.errors # type: ignore[import]
from googleapiclient.discovery import build # type: ignore[import]
except ImportError as exc:
raise ImportError(
"You must run "
Expand All @@ -61,17 +61,22 @@ def _get_identity_metadata_from_id(self, id: str)-> List[str]:
"to load authorization identities."
) from exc

authorized_identities = []
authorized_identities: list = []
creds = self._load_credentials()
service = build("drive", "v3", credentials=creds) # Build the service
try:
permissions = service.permissions().list(fileId=id).execute()
except googleapiclient.errors.HttpError:
print(f"You dont have permission to retrieve permission for the file \
with fileId: {id}")
print(
f"insufficientFilePermissions: The user does not have sufficient \
permissions to retrieve permission for the file with fileId: {id}"
)
return authorized_identities
except Exception as exc:
print(f"Error occured while fetching permission for the file with fileId: {id}")
print(
f"Error occurred while fetching the permissions for the file with \
fileId: {id}"
)
print(f"Error: {exc}")
return authorized_identities

Expand Down Expand Up @@ -154,7 +159,7 @@ def _load_credentials(self) -> Any:
)
except ImportError:
raise ImportError(
"You must run "
"Install prerequisites by running: "
"`pip install --upgrade "
"google-api-python-client google-auth-httplib2 "
"google-auth-oauthlib` "
Expand Down

0 comments on commit 89b8fe8

Please sign in to comment.