'positional argument error in sheduling task in python

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)


Solution 1:[1]

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))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 crystalAhmet