我已在 Google Developers Console 上注册,但我的项目不是计费项目。我做了“初始化环境”的步骤。和“构建和运行”,如网页https://github.com/GoogleCloudPlatform/datalab/wiki/Development-Environment和https://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.')
不知道是我的配置错误还是云数据实验室不支持本地部署和运行。也就是说,我们无法在本地数据实验室服务器上运行笔记本中的代码。请给我一些想法。这个问题困扰了我一个星期!谢谢!