【问题标题】:Is there a way to specify exact path to "client_secret.json"有没有办法指定“client_secret.json”的确切路径
【发布时间】:2019-05-13 16:33:19
【问题描述】:

我对这些东西很陌生,我现在真的不知道该怎么做,我需要能够输入“client_secret.json”文件的确切路径,但在每个教程中我看到它只使用文件名相同的目录,但我的不是。

creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)

【问题讨论】:

    标签: python google-api gspread


    【解决方案1】:

    是的,任何接受文件名的地方都将接受绝对或相对路径。您正在谈论相对路径(位于同一目录中),您可以使用以下方式:

    creds = ServiceAccountCredentials.from_json_keyfile_name('../client_secret.json', scope)
    

    ../ 指定上一个文件夹,然后查找您的文件。此外,您可以使用绝对路径,例如:

    creds = ServiceAccountCredentials.from_json_keyfile_name('C:\\Users\\myUser\\Desktop\\client_secret.json', scope)
    

    通常建议使用相对路径,因为这样您可以将整个项目文件夹移动到另一个地方/驱动器,而不会破坏所有链接。

    相对路径也可以在树中上下导航,例如:

    creds = ServiceAccountCredentials.from_json_keyfile_name('../../../SomeFolder/SubFolder/client_secret.json', scope)
    

    【讨论】:

    • 很好,谢谢,idk,但我记得尝试过那个...它没有奏效,但现在它奏效了,这有点令人困惑,因为这里没有太多关于这些东西的信息。
    猜你喜欢
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 2019-12-22
    • 2013-05-05
    • 1970-01-01
    • 2021-10-31
    • 2014-01-02
    • 2021-12-31
    相关资源
    最近更新 更多