Support default env credentials (e.g. needed in Google Colaboratory (Colab)) + workaround for now
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- authentication
Hướng nghiên cứu
Bắt đầu trong pydrive2/auth.py, đặc biệt là luồng GoogleAuth xoay quanh LoadClientConfig, GetFlow và LocalWebserverAuth, rồi so sánh với import hook pydrive của Google Colaboratory được liên kết. Tái hiện lỗi Colab và xác minh rằng thông tin xác thực của môi trường mặc định có thể xác thực mà không cần monkey patch hoặc workaround client_secrets.json.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Google Colaboratory provides these instructions for using PyDrive: https://colab.research.google.com/notebooks/snippets/drive.ipynb#scrollTo=bRFyEsdfBxJ9
Running the same code, but substituting pydrive2 for pydrive, produces errors as collapsed here.
FileNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/oauth2client/clientsecrets.py in _loadfile(filename)
120 try:
--> 121 with open(filename, 'r') as fp:
122 obj = json.load(fp)
FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets.json'
During handling of the above exception, another exception occurred:
InvalidClientSecretsError Traceback (most recent call last)
9 frames
/usr/local/lib/python3.7/dist-packages/pydrive2/auth.py in LoadClientConfigFile(self, client_config_file)
476 client_type, client_info = clientsecrets.loadfile(
--> 477 client_config_file
478 )
/usr/local/lib/python3.7/dist-packages/oauth2client/clientsecrets.py in loadfile(filename, cache)
164 if not cache:
--> 165 return _loadfile(filename)
166
/usr/local/lib/python3.7/dist-packages/oauth2client/clientsecrets.py in _loadfile(filename)
124 raise InvalidClientSecretsError('Error opening file', exc.filename,
--> 125 exc.strerror, exc.errno)
126 return _validate_clientsecrets(obj)
InvalidClientSecretsError: ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
During handling of the above exception, another exception occurred:
InvalidConfigError Traceback (most recent call last)
<ipython-input-3-e7c1a9729564> in <module>()
16 uploaded = drive.CreateFile({'title': 'Sample file.txt'})
17 uploaded.SetContentString('Sample upload file content')
---> 18 uploaded.Upload()
19 print('Uploaded file with ID {}'.format(uploaded.get('id')))
/usr/local/lib/python3.7/dist-packages/pydrive2/files.py in Upload(self, param)
495 self._FilesPatch(param=param)
496 else:
--> 497 self._FilesInsert(param=param)
498
499 def Trash(self, param=None):
/usr/local/lib/python3.7/dist-packages/pydrive2/auth.py in _decorated(self, *args, **kwargs)
58 self.auth.ServiceAuth()
59 else:
---> 60 self.auth.LocalWebserverAuth()
61
62 # Initialise service if not built yet.
/usr/local/lib/python3.7/dist-packages/pydrive2/auth.py in _decorated(self, *args, **kwargs)
122 self.LoadCredentials()
123 if self.flow is None:
--> 124 self.GetFlow()
125 if self.credentials is None:
126 code = decoratee(self, *args, **kwargs)
/usr/local/lib/python3.7/dist-packages/pydrive2/auth.py in GetFlow(self)
565 config in self.client_config for config in self.CLIENT_CONFIGS_LIST
566 ):
--> 567 self.LoadClientConfig()
568 constructor_kwargs = {
569 "redirect_uri": self.client_config["redirect_uri"],
/usr/local/lib/python3.7/dist-packages/pydrive2/auth.py in LoadClientConfig(self, backend)
454 )
455 if backend == "file":
--> 456 self.LoadClientConfigFile()
457 elif backend == "settings":
458 self.LoadClientConfigSettings()
/usr/local/lib/python3.7/dist-packages/pydrive2/auth.py in LoadClientConfigFile(self, client_config_file)
478 )
479 except clientsecrets.InvalidClientSecretsError as error:
--> 480 raise InvalidConfigError("Invalid client secrets file %s" % error)
481 if client_type not in (
482 clientsecrets.TYPE_WEB,
InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
The google-colab package would monkey-patch pydrive to avoid these errors.
To monkey-patch pydrive2 in the same way, you need to:
import httplib2
from oauth2client.contrib.gce import AppAssertionCredentials
from pydrive2.auth import GoogleAuth
old_local_webserver_auth = GoogleAuth.LocalWebserverAuth
def LocalWebServerAuth(self, *args, **kwargs):
if isinstance(self.credentials, AppAssertionCredentials):
self.credentials.refresh(httplib2.Http())
return
return old_local_webserver_auth(self, *args, **kwargs)
GoogleAuth.LocalWebserverAuth = LocalWebServerAuth
Then, you can use the same code as in Google Colaboratory's instructions.
- Ngôn ngữ chính
- Python
- Star
- 668
- Fork
- 75
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của iterative/PyDrive2
-
Is this abandon ware?Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
-
Update cryptography to 44.0.0Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Tất cả issue của iterative/PyDrive2
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
topoteretes/cognee#5647 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Sendspin/sendspin-python-cli#291 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Assertion-shape guard fails on development: vacuous recorded-iteration assertion in the assetLinks batch_get helper testCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
awslabs/visual-asset-management-system#414 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modelcontextprotocol/python-sdk#3670 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
aicell-lab/bioengine#232 ·
Maintainer thường phản hồi trong vòng 1 ngày