我在 Python 中运行以下代码以从数据实验室笔记本连接到大查询 api:
!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(最近一次调用最后一次)
----> 5 个凭据 = 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 """这个 Credentials 对象是否是无范围的。
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _implicit_credentials_from_gce() 1123 def _in_gce_environment(): 1124 """检测代码是否在计算引擎环境中运行。-> 1125 1126返回: 1127 如果在 GCE 环境中运行,则返回 True,否则返回 False。
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _get_application_default_credential_GCE() 1378 credentials:要保存到公知文件的凭证;1379 它应该是 GoogleCredentials 的一个实例 -> 1380 well_known_file:1381 保存凭据的文件的名称;此参数应该仅用于 1382 测试
/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.客户端导入 AssertionCredentials 28
ImportError:无法导入名称 HttpAccessTokenRefreshError
我错过了什么?为什么这个谷歌提供的例子不适用于数据实验室?