gpt4 book ai didi

python - "takes 0 positional arguments but 1 was given"错误

转载 作者:行者123 更新时间:2023-12-05 09:11:56 25 4
gpt4 key购买 nike

我正在 Google Cloud Functions 上运行下面的 python 脚本。测试脚本时出现以下错误:

错误:函数终止。建议的操作:检查日志以了解终止原因。细节:
run() 接受 0 个位置参数,但给出了 1 个

这是什么意思?

这是我的脚本:

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

最佳答案

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

链接文章中的代码有def hello_world(request),在这种情况下,request 是调用云函数时传递的参数。 AWS Lambda 类似,因为它们将来自客户端的任何 URL 参数或 JSON 负载打包到此 request 参数中,所以这可能就是这里发生的事情。

我建议在 run 的定义中添加一个参数。这将修复您的错误,检查参数将使您深入了解 Google 云函数平台自动发送到您的代码的信息类型。

关于python - "takes 0 positional arguments but 1 was given"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com