Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google bigquery 身份验证-从计算引擎连接到datalab_Google Bigquery_Google Cloud Datalab - Fatal编程技术网

Google bigquery 身份验证-从计算引擎连接到datalab

Google bigquery 身份验证-从计算引擎连接到datalab,google-bigquery,google-cloud-datalab,Google Bigquery,Google Cloud Datalab,我想从datalab连接到bigQuery并执行更新命令。 我为API和身份验证运行以下代码: from google.cloud import bigquery # Get everything we possibly can from the service account JSON file #set GOOGLE_APPLICATION_CREDENTIALS cred = bigquery.Client.from_service_account_json('OrielResearch

我想从datalab连接到bigQuery并执行更新命令。 我为API和身份验证运行以下代码:

from google.cloud import bigquery

# Get everything we possibly can from the service account JSON file
#set GOOGLE_APPLICATION_CREDENTIALS
cred = bigquery.Client.from_service_account_json('OrielResearch-da46e752c7ff.json')
# Instantiates a client
client = bigquery.Client(project='speedy-emissary-167213',credentials=cred)
# The name of the dataset
dataset_name = 'pgp_orielresearch'
# The name of the table
table_name = 'update_queries'
# Perform a synchronous query.
QUERY = (
    'SELECT * FROM [speedy-emissary-167213:pgp_orielresearch.update_queries]')
query = client.run_sync_query(QUERY)
dataset = client.dataset(dataset_name)
tables, token = dataset.list_tables()
并获取以下错误: AttributeError:“客户端”对象没有“授权”属性

有什么想法吗

完整堆栈是:

AttributeErrorTraceback (most recent call last)
<ipython-input-2-616f54fa35ba> in <module>()
     19 query = client.run_sync_query(QUERY)
     20 dataset = client.dataset(dataset_name)
---> 21 t = dataset.list_tables()
     22 #query.timeout_ms = TIMEOUT_MS
     23 #query.run()

/usr/local/lib/python2.7/dist-packages/google/cloud/bigquery/dataset.py in list_tables(self, max_results, page_token)
    568         connection = self._client.connection
    569         resp = connection.api_request(method='GET', path=path,
--> 570                                       query_params=params)
    571         tables = [Table.from_api_repr(resource, self)
    572                   for resource in resp.get('tables', ())]

/usr/local/lib/python2.7/dist-packages/google/cloud/connection.pyc in api_request(self, method, path, query_params, data, content_type, api_base_url, api_version, expect_json, _target_object)
    344         response, content = self._make_request(
    345             method=method, url=url, data=data, content_type=content_type,
--> 346             target_object=_target_object)
    347 
    348         if not 200 <= response.status < 300:

/usr/local/lib/python2.7/dist-packages/google/cloud/connection.pyc in _make_request(self, method, url, data, content_type, headers, target_object)
    242         headers['User-Agent'] = self.USER_AGENT
    243 
--> 244         return self._do_request(method, url, headers, data, target_object)
    245 
    246     def _do_request(self, method, url, headers, data,

/usr/local/lib/python2.7/dist-packages/google/cloud/connection.pyc in _do_request(self, method, url, headers, data, target_object)
    270         :returns: The HTTP response object and the content of the response.
    271         """
--> 272         return self.http.request(uri=url, method=method, headers=headers,
    273                                  body=data)
    274 

/usr/local/lib/python2.7/dist-packages/google/cloud/connection.pyc in http(self)
    101             self._http = httplib2.Http()
    102             if self._credentials:
--> 103                 self._http = self._credentials.authorize(self._http)
    104         return self._http
    105 

AttributeError: 'Client' object has no attribute 'authorize'

正在尝试这样设置凭据:

import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'OrielResearch-da46e752c7ff.json'
from google.cloud.bigquery.client import Client

client = Client()

我从谷歌云引擎连接到数据实验室,而不是从本地机器