如何从本地 PC 上安装的 pycharm 访问 BigQuery

How to access to BigQuery from pycharm installed on Local PC

这里是新手,想知道是否有办法让我从本地 PC 访问 Google 云的项目,并与它上面的项目进行交互?是否涉及任何AUTH?我正在使用 Pycharm,除了我已经安装的 Python 云客户端库,我还安装了 Google 云 SDK

假设您想在 Python 中执行此操作,我将按照此处的说明进行操作: https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-usage-python

您可以在以下位置找到有关 Python 客户端的更多详细信息:

https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/usage.html

我按照以下步骤做了什么,请告诉我我的步骤是否正确,我会尝试 google 更多关于与时间范围相关的错误:

  1. 按照以下 URL 指南创建服务帐户

https://cloud.google.com/docs/authentication/getting-started

2.Try 使用服务帐户密钥访问 Bigquery: https://cloud.google.com/bigquery/docs/authentication/service-account-file

所以我的代码通常看起来像:

从 google.cloud 导入 bigquery

def explicit():

    bigquery_client = bigquery.Client.from_service_account_json('d:\hope-training-portal-2-3d15a04538e8.json')

    # Make an authenticated API request
    buckets = list(bigquery_client.list_datasets())
    print(buckets)

但出现错误: C:\Python27\python.exe C:/Users/emma/PycharmProjects/GCP/INIT.py

追溯(最近调用最后):

文件 "C:/Users/emma/PycharmProjects/GCP/INIT.py",第 45 行,在

explicit()

文件 "C:/Users/emma/PycharmProjects/GCP/INIT.py",第 13 行,显式

buckets = list(bigquery_client.list_datasets())

文件 "C:\Python27\lib\site-packages\google\cloud\iterator.py",第 218 行,在 _items_iter

for page in self._page_iter(increment=False):

文件 "C:\Python27\lib\site-packages\google\cloud\iterator.py",第 248 行,在 _page_iter

page = self._next_page()

文件 "C:\Python27\lib\site-packages\google\cloud\iterator.py",第 348 行,在 _next_page

response = self._get_next_page_response()

文件 "C:\Python27\lib\site-packages\google\cloud\iterator.py",第 399 行,在 _get_next_page_response

query_params=params)

文件 "C:\Python27\lib\site-packages\google\cloud_http.py",第 290 行,在 api_request

headers=headers, target_object=_target_object)

文件 "C:\Python27\lib\site-packages\google\cloud_http.py",第 183 行,在 _make_request

return self._do_request(method, url, headers, data, target_object)

文件 "C:\Python27\lib\site-packages\google\cloud_http.py",第 212 行,在 _do_request

url=url, method=method, headers=headers, data=data)

请求中的文件 "C:\Python27\lib\site-packages\google\auth\transport\requests.py",第 176 行

self._auth_request, method, url, request_headers)

文件 "C:\Python27\lib\site-packages\google\auth\credentials.py",第 121 行,在 before_request

self.refresh(request)

文件 "C:\Python27\lib\site-packages\google\oauth2\service_account.py",第 310 行,正在刷新

request, self._token_uri, assertion)

文件 "C:\Python27\lib\site-packages\google\oauth2_client.py",第 143 行,在 jwt_grant

response_data = _token_endpoint_request(request, token_uri, body)

文件 "C:\Python27\lib\site-packages\google\oauth2_client.py",第 109 行,在 _token_endpoint_request

_handle_error_response(response_body)

文件 "C:\Python27\lib\site-packages\google\oauth2_client.py",第 59 行,在 _handle_error_response

error_details, response_body)

google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT: Token must be a short-lived token and in a reasonable timeframe', u'{\n  "error" : "invalid_grant",\n  "error_description" : "Invalid JWT: Token must be a short-lived token and in a reasonable timeframe"\n}')