langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.16k stars 14.7k forks source link

GoogleDriveLoader: AttributeError: 'Credentials' object has no attribute 'with_scopes' #6997

Closed chrisedington closed 1 year ago

chrisedington commented 1 year ago

System Info

Macbook OSX Python 3.11.4 (main, Jun 25 2023, 18:18:14) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin LangChain Environment: sdk_version:0.0.17 library:langchainplus_sdk platform:macOS-13.3.1-arm64-arm-64bit runtime:python runtime_version:3.11.4

I'm getting this error, and no matter what configurations I try, I cannot get past it.

AttributeError: 'Credentials' object has no attribute 'with_scopes'

My abbreviated code snippet:

from langchain.document_loaders import GoogleDriveLoader
loader = GoogleDriveLoader(
    folder_id="xxxx",    recursive=True,
)

docs = loader.load()
cat ~/.credentials/credentials.json
{
  "installed": {
    "client_id": "xxxxxxxxx.apps.googleusercontent.com",
    "project_id": "xxxxxxxxx",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxxxxxxx",
    "redirect_uris": [
      "http://localhost"
    ]
  }
}
#gcloud info

Google Cloud SDK [437.0.1]

Platform: [Mac OS X, arm] uname_result(system='Darwin', node='xxxxs-MBP-3', release='22.4.0', version='Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000', machine='arm64')
Locale: (None, 'UTF-8')
Python Version: [3.11.4 (main, Jun 25 2023, 18:18:14) [Clang 14.0.3 (clang-1403.0.22.14.1)]]
Python Location: [/Users/xxxx/.asdf/installs/python/3.11.4/bin/python3]
OpenSSL: [OpenSSL 1.1.1u  30 May 2023]
Requests Version: [2.25.1]
urllib3 Version: [1.26.9]
Default CA certs file: [/Users/xxxx/google-cloud-sdk/lib/third_party/certifi/cacert.pem]
Site Packages: [Disabled]

Installation Root: [/Users/xxxx/google-cloud-sdk]
Installed Components:
  gsutil: [5.24]
  core: [2023.06.30]
  bq: [2.0.93]
  gcloud-crc32c: [1.0.0]
System PATH: [/Users/xxxx/.asdf/plugins/python/shims:/Users/xxxx/.asdf/installs/python/3.11.4/bin:/Users/xxxx/.rvm/gems/ruby-3.0.3/bin:/Users/xxxx/.rvm/gems/ruby-3.0.3@global/bin:/Users/xxxx/.rvm/rubies/ruby-3.0.3/bin:/Users/xxxx/.rvm/bin:/Users/xxxx/google-cloud-sdk/bin:/Users/xxxx/.asdf/shims:/opt/homebrew/opt/asdf/libexec/bin:/Users/xxxx/.sdkman/candidates/gradle/current/bin:/Users/xxxx/.jenv/shims:/Users/xxxx/.jenv/bin:/Users/xxxx/.nvm/versions/node/v17.6.0/bin:/opt/homebrew/opt/mysql@5.7/bin:/opt/homebrew/opt/mysql-client/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/xxxx/Library/Android/sdk/emulator:/Users/xxxx/Library/Android/sdk/platform-tools]
Python PATH: [/Users/xxxx/google-cloud-sdk/lib/third_party:/Users/xxxx/google-cloud-sdk/lib:/Users/xxxx/.asdf/installs/python/3.11.4/lib/python311.zip:/Users/xxxx/.asdf/installs/python/3.11.4/lib/python3.11:/Users/xxxx/.asdf/installs/python/3.11.4/lib/python3.11/lib-dynload]
Cloud SDK on PATH: [True]
Kubectl on PATH: [/usr/local/bin/kubectl]

Installation Properties: [/Users/xxxx/google-cloud-sdk/properties]
User Config Directory: [/Users/xxx/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [/Users/xxxx/.config/gcloud/configurations/config_default]

Account: [xxxxxx@xxx.com]
Project: [project-name-replaced]

Current Properties:
  [compute]
    zone: [europe-west1-b] (property file)
    region: [europe-west1] (property file)
  [core]
    account: [xxxxxx@xxx.com] (property file)
    disable_usage_reporting: [True] (property file)
    project: [project-name-replaced] (property file)

Logs Directory: [/Users/xxx/.config/gcloud/logs]
Last Log File: [/Users/xxx/.config/gcloud/logs/xxxx.log]

git: [git version 2.39.2]
ssh: [OpenSSH_9.0p1, LibreSSL 3.3.6]

Who can help?

@eyurtsev I think?

Information

Related Components

Reproduction

It's happening with a base app, nothing special. Using this template:

https://github.com/hwchase17/langchain-streamlit-template

Expected behavior

Expected to get the oAuth window?

dosubot[bot] commented 1 year ago

Answer generated by a 🤖

Answer

The error message 'Credentials' object has no attribute 'with_scopes' suggests that the Google API client libraries are not up-to-date or not correctly installed.

The with_scopes method is a part of the google.auth.credentials.Credentials class in the google-auth library. If this method is not found, it's likely that the library is outdated or not installed correctly.

You can try to update the google-auth library and other related libraries by running the following command:

!pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

If the problem persists, you might want to check the version of the google-auth library and make sure it's compatible with the version of Python you're using. You can check the version of the google-auth library by running:

import google.auth
print(google.auth.__version__)

If the version is not compatible with your Python version, you might need to downgrade or upgrade your Python version, or install a compatible version of the google-auth library.

In the context shared, it's also important to note that the GoogleDriveLoader in LangChain uses the from_service_account_file method from the google.oauth2.service_account module to load credentials when a service account key exists. Make sure that the service account key file exists at the specified location and is correctly formatted. If you're using a service account, ensure that it has the necessary permissions to access the Google Drive API.

From the new context shared, it appears that you're using the flow.run_local_server(port=0) method to get credentials. This method is typically used in a desktop application where a local server can be run to handle the OAuth2 flow. If you're running your code in a non-interactive environment (like a server or a Docker container), this method might not work. In such cases, you might want to consider using a service account or another method to authenticate your application.

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

chrisedington commented 1 year ago

For anyone who comes across this, I simply set the environment varaible.

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/creds.json"
sivakumar41 commented 6 months ago

from langchain_community.document_loaders import GoogleDriveLoader import os

loader = GoogleDriveLoader( document_ids=["1RLXMPHepwaL2lZ6Ag--5WbsY3NnhZkD2"], recursive=True )

loader.load() file not foundError Traceback (most recent call last) Cell In[29], line 9 2 import os 4 loader = GoogleDriveLoader( 5 document_ids=["1RLXMPHepwaL2lZ6Ag--5WbsY3NnhZkD2"], 6 recursive=True 7 ) ----> 9 loader.load()

File c:\Users\siva.kotagiri\OneDrive - Nimble Accounting\Desktop\Kore.ai\search-assist\for images\env\lib\site-packages\langchain_community\document_loaders\googledrive.py:358, in GoogleDriveLoader.load(self) 354 return self._load_documents_from_folder( 355 self.folder_id, file_types=self.file_types 356 ) 357 elif self.document_ids: --> 358 return self._load_documents_from_ids() 359 else: 360 return self._load_file_from_ids()

File c:\Users\siva.kotagiri\OneDrive - Nimble Accounting\Desktop\Kore.ai\search-assist\for images\env\lib\site-packages\langchain_community\document_loaders\googledrive.py:294, in GoogleDriveLoader._load_documents_from_ids(self) 291 if not self.document_ids: 292 raise ValueError("document_ids must be set") --> 294 return [self._load_document_from_id(doc_id) for doc_id in self.document_ids]

File c:\Users\siva.kotagiri\OneDrive - Nimble Accounting\Desktop\Kore.ai\search-assist\for images\env\lib\site-packages\langchain_community\document_loaders\googledrive.py:294, in (.0) ... --> 198 with open(client_secrets_file, "r") as json_file: 199 client_config = json.load(json_file) 201 return cls.from_client_config(client_config, scopes=scopes, **kwargs)

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\siva.kotagiri\.credentials\credentials.json' Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

im unable to set the path please any one help me. Im placing the credentiasl.json correctly even though im facing the above error