Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:31:25+00:00 2026-06-07T04:31:25+00:00

I am trying to load a CSV file to BigQuery using a python script

  • 0

I am trying to load a CSV file to BigQuery using a python script modelled on the python sample code here: https://developers.google.com/bigquery/docs/developers_guide

But I’m running into the following error when I try to load a table with the REST API:

{'status': '200', 'content-length': '1492', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'server': 'HTTP Upload Server Built on Jun 14 2012 02:12:09 (1339665129)', 'etag': '"tcivyOj9QvKAbuEJ5MEMf9we85w/-mxYhUDjvvydxcebR8fXI6l_5RQ"', 'pragma': 'no-cache', 'cache-control': 'no-cache, no-store, must-revalidate', 'date': 'Fri, 06 Jul 2012 22:30:55 GMT', 'content-type': 'application/json'}

{
 "kind": "bigquery#job",
 "etag": "\"tcivyOj9QvKAbuEJ5MEMf9we85w/-mxYhUDjvvydxcebR8fXI6l_5RQ\"",
 "id": "firespotter.com:firespotter:job_d6b99265278b4c0da9c3033acf39d6b2",
 "selfLink": "https://www.googleapis.com/bigquery/v2/projects/firespotter.com:firespotter/jobs/job_d6b99265278b4c0da9c3033acf39d6b2",
 "jobReference": {
  "projectId": "firespotter.com:firespotter",
  "jobId": "job_d6b99265278b4c0da9c3033acf39d6b2"
 },
 "configuration": {
  "load": {
   "schema": {
    "fields": [
     {
      "name": "date",
      "type": "STRING"
     },
     {
      "name": "time",
      "type": "STRING"
     },
     {
      "name": "call_uuid",
      "type": "STRING"
     },
     {
      "name": "log_level",
      "type": "STRING"
     },
     {
      "name": "file_line",
      "type": "STRING"
     },
     {
      "name": "message",
      "type": "STRING"
     }
    ]
   },
   "destinationTable": {
    "projectId": "385479794093",
    "datasetId": "telephony_logs",
    "tableId": "table_name"
   },
   "createDisposition": "CREATE_IF_NEEDED",
   "writeDisposition": "WRITE_TRUNCATE",
   "encoding": "UTF-8"
  }
 },
 "status": {
  "state": "DONE",
  "errorResult": {
   "reason": "notFound",
   "message": "Not Found: Dataset 385479794093:telephony_logs"
  },
  "errors": [
   {
    "reason": "notFound",
    "message": "Not Found: Dataset 385479794093:telephony_logs"
   }
  ]
 }
}

The projectId listed in the error “385479794093” is not the projectId that I pass in, it’s the “project number”. The projectId should be “firespotter.com:firespotter”:

{
 "kind": "bigquery#datasetList",
 "etag": "\"tcivyOj9QvKAbuEJ5MEMf9we85w/ZMa8z6LKMgWZIqLWh3ti2SsSs4g\"",
 "datasets": [
  {
   "kind": "bigquery#dataset",
   "id": "firespotter.com:firespotter:telephony_logs",
   "datasetReference": {
    "datasetId": "telephony_logs",
    "projectId": "firespotter.com:firespotter"
   }
  }
 ]
}

Why does the REST API insist on supplying its own incorrect projectId, when I pass the correct value in three different places? Is there another place where I need to pass in or set the Project ID?

For reference, here is the relevant code snippet:

PROJECT = 'firespotter.com:firespotter'
DATASET = 'telephony_logs'


FLOW = OAuth2WebServerFlow(
    client_id='385479794093.apps.googleusercontent.com',
    client_secret='<a_secret_here>',
    scope='https://www.googleapis.com/auth/bigquery',
    user_agent='firespotter-upload-script/1.0')

def loadTable(http, projectId, datasetId, tableId, file_path, replace=False):
  url = "https://www.googleapis.com/upload/bigquery/v2/projects/" + projectId + "/jobs"
  # Create the body of the request, separated by a boundary of xxx
  mime_data = ('--xxx\n' +
            'Content-Type: application/json; charset=UTF-8\n' + '\n' +
            '{\n' +
            '   "projectId": "' + projectId + '",\n' +
            '   "configuration": {\n' +
            '     "load": {\n' +
            '       "schema": {\n' +
            '         "fields": [\n' +
            '          {"name":"date", "type":"STRING"},\n' +
            '          {"name":"time", "type":"STRING"},\n' +
            '          {"name":"call_uuid", "type":"STRING"},\n' +
            '          {"name":"log_level", "type":"STRING"},\n' +
            '          {"name":"file_line", "type":"STRING"},\n' +
            '          {"name":"message", "type":"STRING"}\n' +
            '        ]\n' +
            '      },\n' +
            '      "destinationTable": {\n' +
            '        "projectId": "' + projectId + '",\n' +
            '        "datasetId": "' + datasetId + '",\n' +
            '        "tableId": "' + tableId + '"\n' +
            '      },\n' +
            '     "createDisposition": "CREATE_IF_NEEDED",\n' +
            '     "writeDisposition": "' + ('WRITE_TRUNCATE' if replace else 'WRITE_APPEND') + '",\n' +
            '     "encoding": "UTF-8"\n' +
            '    }\n' +
            '  }\n' +
            '}\n' +
            '--xxx\n' +
            'Content-Type: application/octet-stream\n' +
            '\n')
  # Append data from the specified file to the request body
  f = open(file_path, 'r')
  header_line = f.readline()  # skip header line
  mime_data += f.read()

  # Signify the end of the body
  mime_data += ('--xxx--\n')

  headers = {'Content-Type': 'multipart/related; boundary=xxx'}
  resp, content = http.request(url, method="POST", body=mime_data, headers=headers)
  print str(resp) + "\n"
  print content

# --- Main ----------------------------------------------
def main(argv):

  csv_path = args[0]

  # If the credentials don't exist or are invalid, run the native client
  # auth flow. The Storage object will ensure that if successful the good
  # credentials will get written back to a file.
  storage = Storage('bigquery2_credentials.dat') # Choose a file name to store the credentials.
  credentials = storage.get()
  if credentials is None or credentials.invalid:
    credentials = run(FLOW, storage)

  # Create an httplib2.Http object to handle our HTTP requests and authorize it
  # with our good credentials.
  http = httplib2.Http()
  http = credentials.authorize(http)

  loadTable(http, PROJECT, DATASET, 'table_name', csv_path, replace=True)

if __name__ == '__main__':
  main(sys.argv)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:31:27+00:00Added an answer on June 7, 2026 at 4:31 am

    Did you recently set the project id to firespotter.com:firespotter? If the dataset was created before the project was named, there will be a mismatch between the old project id and the new. There is an automated system that updates project ids, but it is possible that it hasn’t run yet or is having a problem (I’m on vacation right now, so can’t check). Hopefully, if you retry again some time soon it will just work. If not, let us know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load csv file using SQLXMLBULKLOADLib which first converts csv to
Im trying to load a csv file into a datatable using oledb. This is
I am trying to create a csv file using python that is truly Excel-compatible
I am trying to load a CSV file into an array using ColdFusion (version
I am trying to load a CSV file in to mySQL database using Java+Hibernate+Spring.
I am trying to figure out an eazy way to load CSV file into
I have my csv file in my public folder, and i'm trying to load
I am trying to load a csv file that has 14 columns like this:
I'm trying to load a CSV file into a single dimentional array. I can
I'm trying to Load a CSV file into my MySQL database, But I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.