簡體   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.

部署是正確的,但是當我觸發 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.

知道我做錯了什么嗎??? 這是我的代碼的簡化版本:

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

[已解決]問題是我忘記了語句return ('some message', http_code)

例如: 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM