简体   繁体   English

谷歌云 Function + bigquery:内部服务器错误

[英]Google Cloud Function + bigquery: Internal Server Error

I'm making a Google cloud Function with python that requests data to an API, perform an ETL, and finally put the resulting panda's dataframe in a big query table. I'm making a Google cloud Function with python that requests data to an API, perform an ETL, and finally put the resulting panda's dataframe in a big query table.

The deploy is correct, but when I trigger the function (HTTP trigger) I get this error:部署是正确的,但是当我触发 function(HTTP 触发器)时,我收到此错误:

Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Any idea of what I'am doing wrong???知道我做错了什么吗??? Here is a simplified version of my code:这是我的代码的简化版本:

import pandas as pd
from google.cloud import bigquery, error_reporting
from bigquery_tools import update_table

def main(request):

  if request:
    try:
        # BIGQUERY CLIENT
        BIGQUERY_CREDENTIALS = "credentials.json"
        BIGQUERY_PROJECT_ID = "my_project_id"
        BIGQUERY_DATASET_ID = "my_dataset_id"
        TABLE_ID = "my_table"
        CLIENT = bigquery.Client(project=BIGQUERY_PROJECT_ID)

        # SOME DATAFRAME
        df = pd.DataFrame({
            "debug": ["debug_a"]
        })
        
        # SAVE TO BIGQUERY
        try:
            dataset_ref = CLIENT.dataset(BIGQUERY_DATASET_ID)
            table_ref = dataset_ref.table(TABLE_ID)
            job_config = bigquery.LoadJobConfig()
            job_config.source_format = bigquery.SourceFormat.PARQUET
            job_config.autodetect = True
            job_config.write_disposition = bigquery.WriteDisposition.WRITE_TRUNCATE

            job = CLIENT.load_table_from_dataframe(
                df,
                table_ref,
                job_config=job_config
            )
            job.result()  # Waits for table load to complete.

        except Exception as e:
            pass
    except Exception as e:
        pass

[SOLVED] the problem was that I forgot the statement return ('some message', http_code) . [已解决]问题是我忘记了语句return ('some message', http_code)

For example: return ('ok',200)例如: return ('ok',200)

        try:
            dataset_ref = CLIENT.dataset(BIGQUERY_DATASET_ID)
            table_ref = dataset_ref.table(TABLE_ID)
            job_config = bigquery.LoadJobConfig()
            job_config.source_format = bigquery.SourceFormat.PARQUET
            job_config.autodetect = True
            job_config.write_disposition = bigquery.WriteDisposition.WRITE_TRUNCATE

            job = CLIENT.load_table_from_dataframe(
                df,
                table_ref,
                job_config=job_config
            )
            job.result()  # Waits for table load to complete.
            return ("ok", 200)
        except Exception as e:
            return ("error", 400)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google GCP Cloud Functions 到 BigQuery 错误 - Google GCP Cloud Functions to BigQuery Error 使用 Cloud Function 将数据加载到 Google Cloud Storage 和 BigQuery - Loading Data to Google Cloud Storage & BigQuery with Cloud Function 连接到Google Cloud SQL时出现内部错误 - internal error when connecting to google cloud SQL 使用 Cloud function 将 TXT 文件转换为 CSV 并在 Google BigQuery 中填充数据 - Convert TXT file into CSV with Cloud function and populate data in Google BigQuery 将日期时间 object 插入 BigQuery 时,Google Cloud function 崩溃 - Google Cloud function crashing when insert datetime object into BigQuery 通过 Google Cloud 从 BigQuery 数据库查询 Function (Python) - Query from a BigQuery database via a Google Cloud Function (Python) 在python应用程序中导入Google Cloud Bigquery api模块时出错 - Error importing Google Cloud Bigquery api module in python app 错误:模块“google.cloud.bigquery_storage”没有属性“BigQueryReadClient” - Error: module 'google.cloud.bigquery_storage' has no attribute 'BigQueryReadClient' 导入google-cloud-bigquery python模块时出错 - error when importing google-cloud-bigquery python module Google Cloud Function 出错 - TabError - Error with Google Cloud Function - TabError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM