"无法提供0个位置参数,但给出了1个"

2024-09-21 17:09:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Google云函数上运行下面的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


Tags: csvrunfrom脚本clientrefconfigcloud
1条回答
网友
1楼 · 发布于 2024-09-21 17:09:56

因为您已经发布了所有的代码,很明显有其他东西在调用您的函数。看一下python中的Google云函数example,看起来您的函数必须被定义为至少接受一个参数。在

链接文章中的代码有def hello_world(request),在本例中,request是调用cloud函数时传递的参数。AWS lambda与之类似,因为它们将来自客户端的任何URL参数或JSON有效负载打包到这个request参数中,所以这里很可能就是这样。在

我建议在run的定义中添加一个参数。这将修复您的错误,检查参数将使您了解Google云功能平台自动向您的代码发送何种信息。在

相关问题 更多 >