首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Google时使用驱动器安装时出错

使用Google时使用驱动器安装时出错
EN

Stack Overflow用户
提问于 2020-09-03 12:32:12
回答 2查看 13.4K关注 0票数 20

我一直在研究Colab:

代码语言:javascript
运行
复制
from google.colab import drive 
.mount('/content/gdrive')

没有问题直到今天。

我不知道为什么会出现这个错误:

代码语言:javascript
运行
复制
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly&response_type=code

Enter your authorization code:
··········
---------------------------------------------------------------------------
TIMEOUT                                   Traceback (most recent call last)
<ipython-input-4-d05fe204dd76> in <module>()
      1 from google.colab import drive
----> 2 drive.mount('/content/gdrive')

4 frames
/usr/local/lib/python3.6/dist-packages/google/colab/drive.py in mount(mountpoint, force_remount, timeout_ms, use_metadata_server)
    223         oauth_prompt,
    224         problem_and_stopped,
--> 225         drive_exited,
    226     ])
    227     if case == 0:

/usr/local/lib/python3.6/dist-packages/pexpect/spawnbase.py in expect(self, pattern, timeout, searchwindowsize, async_, **kw)
    342         compiled_pattern_list = self.compile_pattern_list(pattern)
    343         return self.expect_list(compiled_pattern_list,
--> 344                 timeout, searchwindowsize, async_)
    345 
    346     def expect_list(self, pattern_list, timeout=-1, searchwindowsize=-1,

/usr/local/lib/python3.6/dist-packages/pexpect/spawnbase.py in expect_list(self, pattern_list, timeout, searchwindowsize, async_, **kw)
    370             return expect_async(exp, timeout)
    371         else:
--> 372             return exp.expect_loop(timeout)
    373 
    374     def expect_exact(self, pattern_list, timeout=-1, searchwindowsize=-1,

/usr/local/lib/python3.6/dist-packages/pexpect/expect.py in expect_loop(self, timeout)
    179             return self.eof(e)
    180         except TIMEOUT as e:
--> 181             return self.timeout(e)
    182         except:
    183             self.errored()

/usr/local/lib/python3.6/dist-packages/pexpect/expect.py in timeout(self, err)
    142             exc = TIMEOUT(msg)
    143             exc.__cause__ = None    # in Python 3.x we can use "raise exc from None"
--> 144             raise exc
    145 
    146     def errored(self):

TIMEOUT: <pexpect.popen_spawn.PopenSpawn object at 0x7f58fb7ab4e0>
searcher: searcher_re:
    0: re.compile('google.colab.drive MOUNTED')
    1: re.compile('root@e7a376888b95-b97a84955c154714b7850ceb4ecf0e8e: ')
    2: re.compile('(Go to this URL in a browser: https://.*)$')
    3: re.compile('Drive File Stream encountered a problem and has stopped')
    4: re.compile('drive EXITED')
<pexpect.popen_spawn.PopenSpawn object at 0x7f58fb7ab4e0>
searcher: searcher_re:
    0: re.compile('google.colab.drive MOUNTED')
    1: re.compile('root@e7a376888b95-b97a84955c154714b7850ceb4ecf0e8e: ')
    2: re.compile('(Go to this URL in a browser: https://.*)$')
    3: re.compile('Drive File Stream encountered a problem and has stopped')
    4: re.compile('drive EXITED')

众所周知,这段代码打开了一个新的选项卡,您必须选择一个Google帐户,单击“允许”按钮,然后将一个长密码复制到Colab。

编辑:

我试着用另一种方式做同样的事情:

代码语言:javascript
运行
复制
#Installing PyDrive
!pip install PyDrive

#Importing modules
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

#Authenticating and creating the PyDrive client
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

#Getting the file
downloaded2 = drive.CreateFile({'id':"1QGtoo1wqCP2yrjl8kFu4kTfjWqh3EOdt"})   # replace the id with id of file you want to access
downloaded2.GetContentFile('estructura_cc_felipe.xlsx') 

但是它会引发这样的错误:

代码语言:javascript
运行
复制
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&code_challenge=WkM1RS8Flu1_txc3jn4V_FfutgZuRaHSzYbDvs134PM&code_challenge_method=S256&access_type=offline&response_type=code&prompt=select_account


Enter verification code: ··········
---------------------------------------------------------------------------
AuthorizationError                        Traceback (most recent call last)
<ipython-input-2-bb96e063f8ef> in <module>()
      6 
      7 #Authenticating and creating the PyDrive client
----> 8 auth.authenticate_user()
      9 gauth = GoogleAuth()
     10 gauth.credentials = GoogleCredentials.get_application_default()

1 frames
/usr/local/lib/python3.6/dist-packages/google/colab/auth.py in authenticate_user(clear_output)
    147     context_manager = _output.temporary if clear_output else _noop
    148     with context_manager():
--> 149       _gcloud_login()
    150     _install_adc()
    151     colab_tpu_addr = _os.environ.get('COLAB_TPU_ADDR', '')

/usr/local/lib/python3.6/dist-packages/google/colab/auth.py in _gcloud_login()
     97     _os.remove(name)
     98   if gcloud_process.returncode:
---> 99     raise _errors.AuthorizationError('Error fetching credentials')
    100 
    101 

AuthorizationError: Error fetching credentials

有人知道是怎么回事吗?我已经工作了很长时间,导入文件位于我的谷歌驱动器,从来没有这些问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-03 16:33:18

结果表明,如果您手动地从auth按钮复制auth代码,而不是单击“复制”按钮,它就会工作。

票数 37
EN

Stack Overflow用户

发布于 2022-01-30 13:09:20

以下是您可以尝试的解决方案:

对于新的(混乱的)更新,您不能再使用drive._mount进行安装了(至少现在是这样)。因此,您可以做的是将您的文件夹/目录从您的另一个google驱动器复制到当前的google驱动器(您正在登录到colab的帐户),或者您可以从colab登录并使用您想要挂载的驱动器登录到您的Google帐户。

记住在遵循上述指南之后使用drive.mount而不是drive._mount

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63723763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档