我在Google Cloud Functions上运行下面的python脚本。在测试脚本时,我有以下错误:
Error: function terminated. Recommended action: inspect logs for termination reason. Details: run() takes 0 positional arguments but 1 was given
什么意思?
下面是我的脚本:
from google.cloud import bigquery
client = bigquery.Client()
def run():
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.
在我学习的过程中,我从下面的文档https://google-cloud-python.readthedocs.io/en/0.32.0/bigquery/usage.html中获取了这个脚本
发布于 2019-12-12 23:58:57
由于您已经发布了所有代码,因此很明显有其他东西正在调用您的函数。查看Python语言中的Google Cloud Function example,看起来您的函数必须定义为至少接受一个参数。
链接文章中的代码具有def hello_world(request)
,在本例中,request
是调用云函数时传递的参数。AWS Lambdas也是类似的,因为它们将来自客户端的任何URL参数或JSON有效负载打包到这个request
参数中,所以这可能就是这里发生的事情。
我建议在run
的定义中添加一个参数。这将修复您的错误,检查参数将使您深入了解Google cloud function平台自动向您的代码发送什么样的信息。
https://stackoverflow.com/questions/59314296
复制相似问题