[英]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.