小编Mic*_*ela的帖子

Python 中的 Google BigQuery 查询在使用 result() 时有效,但在使用 to_dataframe() 时出现权限问题

升级 pip 包和返回查询结果的 bigquery 连接器突然停止工作并出现以下错误消息后,我遇到了问题

from google.cloud import bigquery
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file('path/to/file', scopes=['https://www.googleapis.com/auth/cloud-platform',
    'https://www.googleapis.com/auth/drive',
    'https://www.googleapis.com/auth/bigquery'
])

client = bigquery.Client(credentials=credentials)
data = client.query('select * from dataset.table').to_dataframe()
Run Code Online (Sandbox Code Playgroud)

PermissionDenied:403请求失败:用户没有bigquery.readsessions.create'权限

但!如果您将代码切换为

data = client.query('select * from dataset.table').result()
Run Code Online (Sandbox Code Playgroud)

(dataframe -> result) 您收到了 RowIterator 格式的数据并能够正确读取它们。

使用具有相同凭据的 to_dataframe 的相同脚本正在服务器上运行。因此我将bigquery包设置为相同的版本2.28.0,但这仍然没有帮助。

我在任何地方都找不到关于此错误/主题的任何建议,所以我只想分享是否有人遇到同样的事情。

python google-cloud-storage google-bigquery

5
推荐指数
1
解决办法
2467
查看次数