代码之家  ›  专栏  ›  技术社区  ›  Sam Rockett

bigquery中的invalidresponse错误从\u文件加载\u表\u

  •  0
  • Sam Rockett  · 技术社区  · 6 年前

    我试图从一个bytesio对象将一组csv数据上传到一个bigquery中,但始终会出错。 InvalidResponse: Response headers must contain header 'location'

    这是我的密码

    # self.database = authenticated bigquery.Client
    
    config = bigquery.LoadJobConfig()
    config.skip_leading_rows = 1
    config.source_format = bigquery.SourceFormat.CSV
    config.allow_jagged_rows = True
    schema = [
        bigquery.SchemaField("date", "DATE", mode="REQUIRED"),
        bigquery.SchemaField("page_id", "STRING", mode="REQUIRED")
    ]
    # ... Appending a list of bigquery.SchemaField("name", "INTEGER")
    config.schema = schema
    
    table = self.get_or_create_table(name, config.schema) # returns TableReference
    
    file = self.clip_data(local_fp, cutoff_date) # returns BytesIO
    
    job = self.database.load_table_from_file(
        file, table,
        num_retries=self.options.num_retries,
        job_id=uuid.uuid4().int,
        job_config=config
    ) # Error is here.
    

    我试过四处搜索,但找不到任何原因或解决这个例外。

    InvalidResponse: ('Response headers must contain header', 'location')
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Sam Rockett    6 年前

    问题是由于没有提供 location load_table_from_file 方法。

    location="US"
    

    足以解决问题。