尝试通过 python API 创建 bigquery table 时出现异常
Exception when trying to create bigquery table via python API
我正在开发一款可以将事件流式传输到 BQ 中的应用程序。由于 Streamed Inserts 要求 table 预先存在,因此我 运行 使用以下代码来检查 table 是否存在,如果不存在则创建它:
TABLE_ID = "data" + single_date.strftime("%Y%m%d")
exists = False;
request = bigquery.tables().list(projectId=PROJECT_ID,
datasetId=DATASET_ID)
response = request.execute()
while response is not None:
for t in response.get('tables', []):
if t['tableReference']['tableId'] == TABLE_ID:
exists = True
break
request = bigquery.tables().list_next(request, response)
if request is None:
break
if not exists:
print("Creating Table " + TABLE_ID)
dataset_ref = {'datasetId': DATASET_ID,
'projectId': PROJECT_ID}
table_ref = {'tableId': TABLE_ID,
'datasetId': DATASET_ID,
'projectId': PROJECT_ID}
schema_ref = SCHEMA
table = {'tableReference': table_ref,
'schema': schema_ref}
table = bigquery.tables().insert(body=table, **dataset_ref).execute(http)
我是 运行ning python 2.7,并且已经通过 PIP 安装了 google 客户端 API。
当我尝试 运行 脚本时,出现以下错误:
No handlers could be found for logger "oauth2client.util"
Traceback (most recent call last):
File "do_hourly.py", line 158, in <module>
main()
File "do_hourly.py", line 101, in main
body=table, **dataset_ref).execute(http)
File "build/bdist.linux-x86_64/egg/oauth2client/util.py", line 142, in positional_wrapper
File "/usr/lib/python2.7/site-packages/googleapiclient/http.py", line 721, in execute
resp, content = http.request(str(self.uri), method=str(self.method),
AttributeError: 'module' object has no attribute 'request'
我试着研究这个问题,但我能找到的只是关于混淆 urllib、urllib2 和 Python 2.7 / 3 的信息。
我不太确定如何继续此操作,感谢所有帮助。
谢谢!
发现问题出在以下行中,我从 SO thread:
table = bigquery.tables().insert(body=table, **dataset_ref).execute(http)
一旦我删除了我的范围内不存在的 "http" 变量,异常就消失了
我正在开发一款可以将事件流式传输到 BQ 中的应用程序。由于 Streamed Inserts 要求 table 预先存在,因此我 运行 使用以下代码来检查 table 是否存在,如果不存在则创建它:
TABLE_ID = "data" + single_date.strftime("%Y%m%d")
exists = False;
request = bigquery.tables().list(projectId=PROJECT_ID,
datasetId=DATASET_ID)
response = request.execute()
while response is not None:
for t in response.get('tables', []):
if t['tableReference']['tableId'] == TABLE_ID:
exists = True
break
request = bigquery.tables().list_next(request, response)
if request is None:
break
if not exists:
print("Creating Table " + TABLE_ID)
dataset_ref = {'datasetId': DATASET_ID,
'projectId': PROJECT_ID}
table_ref = {'tableId': TABLE_ID,
'datasetId': DATASET_ID,
'projectId': PROJECT_ID}
schema_ref = SCHEMA
table = {'tableReference': table_ref,
'schema': schema_ref}
table = bigquery.tables().insert(body=table, **dataset_ref).execute(http)
我是 运行ning python 2.7,并且已经通过 PIP 安装了 google 客户端 API。
当我尝试 运行 脚本时,出现以下错误:
No handlers could be found for logger "oauth2client.util"
Traceback (most recent call last):
File "do_hourly.py", line 158, in <module>
main()
File "do_hourly.py", line 101, in main
body=table, **dataset_ref).execute(http)
File "build/bdist.linux-x86_64/egg/oauth2client/util.py", line 142, in positional_wrapper
File "/usr/lib/python2.7/site-packages/googleapiclient/http.py", line 721, in execute
resp, content = http.request(str(self.uri), method=str(self.method),
AttributeError: 'module' object has no attribute 'request'
我试着研究这个问题,但我能找到的只是关于混淆 urllib、urllib2 和 Python 2.7 / 3 的信息。
我不太确定如何继续此操作,感谢所有帮助。
谢谢!
发现问题出在以下行中,我从
table = bigquery.tables().insert(body=table, **dataset_ref).execute(http)
一旦我删除了我的范围内不存在的 "http" 变量,异常就消失了