代码之家  ›  专栏  ›  技术社区  ›  Simon Breton

“六”没有定义。要求图书馆问题

  •  0
  • Simon Breton  · 技术社区  · 5 年前

    我正在Google Cloud函数上运行下面的python脚本,出现以下错误:

    Error: function terminated. Recommended action: inspect logs for termination reason. Details: name 'six' is not defined

    from google.cloud import bigquery
    
    client = bigquery.Client()
    
    def run(request):
        csv_file = six.BytesIO(b"""full_name,age
    Phred Phlyntstone,32
    Wylma Phlyntstone,29
    """)
    
        table_ref = dataset.table('ga-online-audit:test_python.test')
        job_config = bigquery.LoadJobConfig()
        job_config.source_format = 'CSV'
        job_config.skip_leading_rows = 1
        job = client.load_table_from_file(
            csv_file, table_ref, job_config=job_config)  # API request
        job.result()  # Waits for table load to complete.
    

    这是我的需求txt文件:

    # Function dependencies, for example:
    # package>=version
    google-cloud-logging
    google-cloud-error-reporting
    google-cloud-bigquery
    six==1.13.0
    
    1 回复  |  直到 5 年前
        1
  •  3
  •   Willis Blackburn    5 年前

    您已经声明了对six的依赖关系,但仍然需要在脚本中导入它。

    import six
    six.BytesIO(...)