我正在在Python下面的代码从数据实验室笔记本连接到大的查询API:无法连接至BigQuery API从DataLab
!pip install google-api-python-client==1.4.2 httplib2==0.9.2 oauth2client==1.5.2 pyasn1==0.1.9 pyasn1-modules==0.0.8 rsa==3.2.3 simplejson==3.8.1 six==1.10.0 uritemplate==0.6 wheel==0.24.0
import httplib2
import time
import datetime as dt
import sys
import subprocess
from googleapiclient import errors
from googleapiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import GoogleCredentials
from googleapiclient.http import MediaFileUpload
import gcp.bigquery as bq
import pandas as pd
credentials = GoogleCredentials.get_application_default()
bigquery_service = build('bigquery', 'v2', credentials=credentials)
我收到以下错误:
ImportError Traceback (most recent call last) in()
----> 5 credentials = GoogleCredentials.get_application_default() 6 7 bigquery_service = build('bigquery', 'v2', credentials=credentials)
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in >get_application_default() 1202 """ 1203 return self -> 1204 1205 @property 1206 def serialization_data(self):
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _get_implicit_credentials(cls) 1187 access_token, client_id, client_secret, refresh_token, 1188 token_expiry, token_uri, user_agent, revoke_uri=revoke_uri) -> 1189 1190 def create_scoped_required(self): 1191 """Whether this Credentials object is scopeless.
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _implicit_credentials_from_gce() 1123 def _in_gce_environment(): 1124 """Detect if the code is running in the Compute Engine environment. -> 1125 1126 Returns: 1127 True if running in the GCE environment, False otherwise.
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _get_application_default_credential_GCE() 1378 credentials: the credentials to be saved to the well known file; 1379 it should be an instance of GoogleCredentials -> 1380 well_known_file: the name of the file where the credentials are to be 1381 saved; this parameter is supposed to be used for 1382 testing only
/usr/local/lib/python2.7/dist-packages/oauth2client/gce.py in() 24 from oauth2client._helpers import _from_bytes 25 from oauth2client import util ---> 26 from oauth2client.client import HttpAccessTokenRefreshError 27 from oauth2client.client import AssertionCredentials 28
ImportError: cannot import name HttpAccessTokenRefreshError
我错过了什么?为什么这个谷歌提供的示例不适用于数据实验室?
为什么不只是使用Datalab中内置的BigQuery支持(在gcp.bigquery和受支持的%bigquery magics中)? –