From c67fadc5c56521b89145c571a7301dff29e2ae1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LEBRUN?= Date: Thu, 15 Oct 2015 12:10:47 -0400 Subject: [PATCH] Fixes for the load by post sample Added sourceFormat in the body New line after the end of the body for the boundary Creation of the scope for the credentials Project ID always in lowercase --- bigquery/api/load_data_by_post.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bigquery/api/load_data_by_post.py b/bigquery/api/load_data_by_post.py index 5527a055176..a10139ae218 100755 --- a/bigquery/api/load_data_by_post.py +++ b/bigquery/api/load_data_by_post.py @@ -60,7 +60,8 @@ def make_post(http, schema, data, project_id, dataset_id, table_id): ' "projectId": "' + project_id + '",\n' + ' "datasetId": "' + dataset_id + '",\n' + ' "tableId": "' + table_id + '"\n' + - ' }\n' + + ' },\n' + + ' "sourceFormat": "NEWLINE_DELIMITED_JSON"' + ' }\n' + ' }\n' + '}\n' + @@ -71,7 +72,7 @@ def make_post(http, schema, data, project_id, dataset_id, table_id): resource += data # Signify the end of the body - resource += ('--xxx--\n') + resource += ('\n--xxx--\n') headers = {'Content-Type': 'multipart/related; boundary=xxx'} @@ -108,6 +109,8 @@ def poll_job(bigquery, job): # [START main] def main(project_id, dataset_id, table_name, schema_path, data_path): credentials = GoogleCredentials.get_application_default() + scope = ['https://www.googleapis.com/auth/bigquery'] + credentials = credentials.create_scoped(scope) http = credentials.authorize(httplib2.Http()) bigquery = discovery.build('bigquery', 'v2', credentials=credentials) @@ -151,7 +154,7 @@ def main(project_id, dataset_id, table_name, schema_path, data_path): args = parser.parse_args() main( - args.project_id, + args.project_id.lower(), args.dataset_id, args.table_name, args.schema_file,