gpt4 book ai didi

python - 错误 : object. __new__() 不带参数

转载 作者:行者123 更新时间:2023-12-01 05:45:44 25 4
gpt4 key购买 nike

我收到以下消息,此功能之前可以工作。我删除了下面的 .delay 函数只是为了生成消息,因为这是一项任务,但通常它看起来像 ProcessRequests.delay.(batch)

object._new_() 不带参数

if request.method == 'POST':                               
batches = Batch.objects.for_user_pending(request.user)
for batch in batches:
ProcessRequests(batch) #ProcessRequests.delay is normally used here
batch.complete_update()

任务:

class ProcessRequests(Task):
name = "Request to Process"
max_retries = 1
default_retry_delay = 3

def run(self, batch):
for e in Contact.objects.filter(contact_owner=batch.user, group=batch.group):
msg = Message.objects.create(
recipient_number=e.mobile,
content=batch.content,
sender=e.contact_owner,
billee=batch.user,
sender_name=batch.sender_name
)
gateway = Gateway.objects.get(pk=2)
msg.send(gateway)

完整错误:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/sms/process

Django Version: 1.5.1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.humanize',
'south',
'sms',
'debug_toolbar')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'async_messages.middleware.AsyncMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "/Users/user/Documents/workspace/s/django-env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/user/Documents/workspace/s/django-env/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
25. return view_func(request, *args, **kwargs)
File "/Users/user/Documents/workspace/s/sms/views.py" in process_all
214. ProcessRequests(batch)

Exception Type: TypeError at /sms/process
Exception Value: object.__new__() takes no parameters

最佳答案

看起来您正在尝试使用参数实例化 ProcessRequests 类,但该类没有接受参数的构造函数,因此会出现错误。

我认为你只需要改变......

ProcessRequests(batch)

...到...

ProcessRequests().run(batch)

...但是它是否会执行您想要的操作取决于 Task 类的定义。

关于python - 错误 : object. __new__() 不带参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16213318/

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