1

我已在 Google Developers Console 上注册,但我的项目不是计费项目。我做了“初始化环境”的步骤。和“构建和运行”,如网页https://github.com/GoogleCloudPlatform/datalab/wiki/Development-Environmenthttps://github.com/GoogleCloudPlatform/datalab/wiki/Build-and-Run描述的。但是当我在部署在本地 linux 服务器上的 Notebook 中运行代码时,我遇到了以下错误:

创建并运行 SQL 查询

bq.Query('SELECT * FROM [cloud-datalab-samples:httplogs.logs_20140615] LIMIT 3').results()

Exception Traceback (most recent call last) in () 1 # 创建并运行 SQL 查询 ----> 2 bq.Query('SELECT * FROM [cloud-datalab-samples:httplogs.logs_20140615] LIMIT 3').results ()

/usr/local/lib/python2.7/dist-packages/gcp/bigquery/_query.pyc in results(self, use_cache) 130 """ 131 if not use_cache or (self._results is None): --> 132 self.execute(use_cache=use_cache) 133 返回 self._results.results 134

/usr/local/lib/python2.7/dist-packages/gcp/bigquery/_query.pyc in execute(self, table_name, table_mode, use_cache, priority, allow_large_results) 343 """ 344 job = self.execute_async(table_name= table_name, table_mode=table_mode, use_cache=use_cache, --> 345 priority=priority, allow_large_results=allow_large_results) 346 self._results = job.wait() 347 return self._results

/usr/local/lib/python2.7/dist-packages/gcp/bigquery/_query.pyc in execute_async(self, table_name, table_mode, use_cache, priority, allow_large_results) 307 allow_large_results=allow_large_results) 308 例外为 e: -- > 309 raise e 310 if 'jobReference' not in query_result: 311 raise Exception('Unexpected query response.')

异常:发送 HTTP 请求失败。 一步一步,我找到了抛出异常的地方: if headers is None: headers = {}

headers['user-agent'] = 'GoogleCloudDataLab/1.0'
# Add querystring to the URL if there are any arguments.
if args is not None:
  qs = urllib.urlencode(args)
  url = url + '?' + qs

# Setup method to POST if unspecified, and appropriate request headers
# if there is data to be sent within the request.
if data is not None:
  if method is None:
    method = 'POST'

  if data != '':
    # If there is a content type specified, use it (and the data) as-is.
    # Otherwise, assume JSON, and serialize the data object.
    if 'Content-Type' not in headers:
      data = json.dumps(data)
      headers['Content-Type'] = 'application/json'
  headers['Content-Length'] = str(len(data))
else:
  if method == 'POST':
    headers['Content-Length'] = '0'

# If the method is still unset, i.e. it was unspecified, and there
# was no data to be POSTed, then default to GET request.
if method is None:
  method = 'GET'

# Create an Http object to issue requests. Associate the credentials
# with it if specified to perform authorization.
#
# TODO(nikhilko):
# SSL cert validation seemingly fails, and workarounds are not amenable
# to implementing in library code. So configure the Http object to skip
# doing so, in the interim.
http = httplib2.Http()
http.disable_ssl_certificate_validation = True
if credentials is not None:
  http = credentials.authorize(http)

try:
  response, content = http.request(url,method=method,body=data,headers=headers)
  if 200 <= response.status < 300:
    if raw_response:
      return content
    return json.loads(content)
  else:
    raise RequestException(response.status, content)
except ValueError:
  raise Exception('Failed to process HTTP response.')
except httplib2.HttpLib2Error:
  raise Exception('Failed to send HTTP request.')

不知道是我的配置错误还是云数据实验室不支持本地部署和运行。也就是说,我们无法在本地数据实验室服务器上运行笔记本中的代码。请给我一些想法。这个问题困扰了我一个星期!谢谢!

4

3 回答 3

1

如果您希望在本地运行 Datalab 容器而不是在 Google Cloud 中运行它,也可以如此处所述: https ://github.com/GoogleCloudPlatform/datalab/wiki/Build-and-Run

但是,这是用于构建/更改 Datalab 代码的开发人员设置,目前不适合希望将 Datalab 用作工具的数据科学家/开发人员。即,与仅将 Datalab 部署到支持计费的云项目相比,它的设置更加复杂。即使使用本地运行的容器,您也可能希望有一个 Google Cloud 项目来运行 BigQuery 查询等

于 2015-11-05T03:54:53.860 回答
0

按照标题为在本地运行 Cloud Datalab 的快速入门指南中的步骤在本地运行 datalab,而无需设置 datalab 开发环境。

于 2016-08-12T00:48:07.127 回答
0

如果您的项目未启用计费,则您无法针对 BigQuery 运行查询,这看起来就像您正在尝试做的那样。

于 2015-10-27T21:26:10.250 回答