Skip to content

Commit c67fadc

Browse files
committed
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
1 parent 6c724cc commit c67fadc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bigquery/api/load_data_by_post.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def make_post(http, schema, data, project_id, dataset_id, table_id):
6060
' "projectId": "' + project_id + '",\n' +
6161
' "datasetId": "' + dataset_id + '",\n' +
6262
' "tableId": "' + table_id + '"\n' +
63-
' }\n' +
63+
' },\n' +
64+
' "sourceFormat": "NEWLINE_DELIMITED_JSON"' +
6465
' }\n' +
6566
' }\n' +
6667
'}\n' +
@@ -71,7 +72,7 @@ def make_post(http, schema, data, project_id, dataset_id, table_id):
7172
resource += data
7273

7374
# Signify the end of the body
74-
resource += ('--xxx--\n')
75+
resource += ('\n--xxx--\n')
7576

7677
headers = {'Content-Type': 'multipart/related; boundary=xxx'}
7778

@@ -108,6 +109,8 @@ def poll_job(bigquery, job):
108109
# [START main]
109110
def main(project_id, dataset_id, table_name, schema_path, data_path):
110111
credentials = GoogleCredentials.get_application_default()
112+
scope = ['https://www.googleapis.com/auth/bigquery']
113+
credentials = credentials.create_scoped(scope)
111114
http = credentials.authorize(httplib2.Http())
112115
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
113116

@@ -151,7 +154,7 @@ def main(project_id, dataset_id, table_name, schema_path, data_path):
151154
args = parser.parse_args()
152155

153156
main(
154-
args.project_id,
157+
args.project_id.lower(),
155158
args.dataset_id,
156159
args.table_name,
157160
args.schema_file,

0 commit comments

Comments
 (0)