Sim*_*ton 4 python python-3.x google-cloud-functions
我正在 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.
Run Code Online (Sandbox Code Playgroud)
据我了解,我从以下文档中获取了此脚本https://google-cloud-python.readthedocs.io/en/0.32.0/bigquery/usage.html
由于您已经发布了所有代码,因此显然有其他东西正在调用您的函数。查看 python 中的 Google Cloud Function示例,看起来您的函数必须定义为至少需要一个参数。
def hello_world(request)在本例中,链接文章中的代码 hasrequest是调用云函数时传递的参数。AWS Lambda 是类似的,因为它们将来自客户端的任何 URL 参数或 JSON 负载打包到此request参数中,因此这可能就是这里发生的情况。
我建议在 的定义中添加一个参数run。这将修复您的错误,并且检查参数将使您深入了解 Google 云函数平台自动发送到您的代码的信息类型。
| 归档时间: |
|
| 查看次数: |
3532 次 |
| 最近记录: |