【问题标题】:Unable to instantiate Google API Service: Permission Denied无法实例化 Google API 服务:权限被拒绝
【发布时间】:2023-04-03 14:15:01
【问题描述】:

我在我的 Google 帐户中创建了一个项目。然后使用自定义搜索引擎的 API 密钥和 ID 授权和访问 Google 自定义搜索。 我尝试通过修改示例代码来使用 Python 界面执行搜索。 每次我在此行之后运行代码时都会收到此错误:

service = build("customsearch", "v1",
        developerKey="AIxx")

IOError: [Errno 13] 权限被拒绝

我尝试自己创建一个请求,以检查问题出在 Google 还是我。这是我的要求:

https://www.googleapis.com/customsearch/v1?q=olive+garden&cx=00026xx&key=AIxx

它奏效了!所以,现在我完全糊涂了,不知道问题出在哪里。

更奇怪的是,当我尝试使用 Google API 资源管理器执行相同的搜索时,它会返回:Daily Limit Exceeded

【问题讨论】:

  • 用超级用户运行,也许对你有帮助。
  • @HasanRamezani 你的意思是使用 sudo 运行 python?
  • 由超级用户运行您的脚本。像这样的东西:sudo python test.py
  • @HasanRamezani 成功了。您知道如何在不需要 sudo 的情况下修复它吗?

标签: python google-api google-custom-search api-key google-api-python-client


【解决方案1】:

问题是因为 httplib2 安装程序没有在 cacerts.txt 上为其他人设置读取权限 您也必须向其他人添加读取权限:D

sudo chmod o+r /Library/Python/2.7/site-packages/httplib2-0.9.2-py2.7.egg/httplib2/cacerts.txt

实际上 httplib2 必须从系统范围的证书中读取此内容,我不知道他们为什么不这样做。有没有人知道为什么?有针对此特定问题的补丁,例如此补丁,例如 https://bugs.mageia.org/show_bug.cgi?id=6568

【讨论】:

【解决方案2】:

问题是因为 Google API 想要访问没有权限的位置。

由超级用户运行您的脚本。像这样:

sudo python test.py

如果您知道Google API要访问的位置,请通过chmod命令更改位置的权限。

【讨论】:

    猜你喜欢
    • 2022-06-26
    • 2019-12-31
    • 2022-08-03
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 2013-12-15
    相关资源
    最近更新 更多