新手在这里,想知道我是否有办法从本地PC访问Google云项目,并与之交互?是否有任何AUTH参与其中?我正在使用Pycharm,除了我已安装它的Python云客户端库,我还安装了Google云SDK
答案 0 :(得分:1)
假设您想在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
答案 1 :(得分:0)
我通过以下步骤做了什么,如果我的步骤正确,请告诉我,并尝试更多地了解与时间框架相关的错误:
https://cloud.google.com/docs/authentication/getting-started
2.尝试使用服务帐户密钥访问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}')