python中的棚架任务中的位置参数错误

发布于 2025-01-28 09:38:25 字数 1253 浏览 5 评论 0原文

当我尝试运行代码时,我遇到了一个位置参数错误,并且do()将额外的参数传递给工作函数,

import schedule
from schedule import Scheduler
import threading
import warnings
import time

def paystack_webhookS (request):
    user = request.user
    remail = payload.customer.email
    rfirst_name = payload.customer.first_name
    amount = payload.data.amount

    first_name = user.first_name
    last_name = user.last_name
    email = user.email

    with transaction.atomic():
            account = Account.objects.select_for_update().get(email = remail)
            account.balance += amount
            asof = account.modified 
            account.save(update_fields=[
                    'balance',
                    'modified',
                    ])


    return HttpResponse(status=200)


schedule.every(10).seconds.do(paystack_webhookS)
schedule.every(10).minutes.do(paystack_webhookS)
schedule.every().hour.do(paystack_webhookS)

while True:
    schedule.run_pending()
    time.sleep(1)

我收到了此错误,

schedule.run_pending()

return view_func(*args, **kwargs)
TypeError: inner() missing 1 required positional argument: 'request'

此错误在尝试执行时会遇到此错误

while True:
    schedule.run_pending()
    time.sleep(1)

I got a positional argument error when i tried running my code and the do() passes extra arguments to the job function

import schedule
from schedule import Scheduler
import threading
import warnings
import time

def paystack_webhookS (request):
    user = request.user
    remail = payload.customer.email
    rfirst_name = payload.customer.first_name
    amount = payload.data.amount

    first_name = user.first_name
    last_name = user.last_name
    email = user.email

    with transaction.atomic():
            account = Account.objects.select_for_update().get(email = remail)
            account.balance += amount
            asof = account.modified 
            account.save(update_fields=[
                    'balance',
                    'modified',
                    ])


    return HttpResponse(status=200)


schedule.every(10).seconds.do(paystack_webhookS)
schedule.every(10).minutes.do(paystack_webhookS)
schedule.every().hour.do(paystack_webhookS)

while True:
    schedule.run_pending()
    time.sleep(1)

i got this error

schedule.run_pending()

return view_func(*args, **kwargs)
TypeError: inner() missing 1 required positional argument: 'request'

this error is gotten when trying to execute

while True:
    schedule.run_pending()
    time.sleep(1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以可爱出名 2025-02-04 09:38:25

您将传递给时间表的功能(您将其命名为“ Paystack_webhooks”)必须在没有任何参数的情况下定义。

def paystack_webhookS():
    ...

您的代码不会告诉“请求”变量来自何处。但是,如果它不是全局,而是在初始化时间表任务时已经定义了,则可以使用包装函数来创建实际的时间表函数:

def createScheduleFunction(requestParameter):
    def __func():
        user = requestParameter.user
        ...
    return func

然后:

schedule.every(10).seconds.do(createScheduleFunction(request))

The function you pass to the schedule (you named it "paystack_webhookS") must be defined without any arguments.

def paystack_webhookS():
    ...

Your code doesn't tell where the "request" variable is coming from. But if it is not global but already defined when the schedule tasks are initialized, you could work with a wrapper function creating your actual schedule function:

def createScheduleFunction(requestParameter):
    def __func():
        user = requestParameter.user
        ...
    return func

And then:

schedule.every(10).seconds.do(createScheduleFunction(request))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文