gpt4 book ai didi

python - 无法 pickle : attribute lookup builtin. 功能失败

转载 作者:太空狗 更新时间:2023-10-29 22:23:00 33 4
gpt4 key购买 nike

我收到下面的错误,只有当我将 delay 添加到 process_upload 函数时才会发生错误,否则它可以正常工作。

有人可以解释这个错误是什么、为什么会发生以及任何解决建议吗?

错误:

PicklingError at /contacts/upload/configurator/47/
Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

这是 View

 if request.method == 'POST':
form = ConfiguratorForm(data=request.POST)
# Send import to task.
process_upload.delay(upload_id=upload.id, form=form)

这就是任务

@task
def process_upload(upload_id, form):
upload = Upload.objects.get(id=upload_id)
upload.process(form=form)

Upload.process 在我的模型中:

 def process(self, form):
self.date_start_processing = timezone.now()
import_this(data=self.filepath, extra_fields=[
{'value': self.group_id, 'position': 5},
{'value': self.uploaded_by.id, 'position': 6}], form=form)

完整跟踪:

Traceback:
File "/Users/user/Documents/workspace/sms/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/sms/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/sms/contacts/views.py" in upload_configurator
118. process_upload.delay(upload_id=upload.id, form=form)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/celery/app/task.py" in delay
357. return self.apply_async(args, kwargs)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/celery/app/task.py" in apply_async
472. **options)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/celery/app/amqp.py" in publish_task
249. **kwargs
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/kombu/messaging.py" in publish
157. compression, headers)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/kombu/messaging.py" in _prepare
233. body) = encode(body, serializer=serializer)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/kombu/serialization.py" in encode
161. payload = encoder(data)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/kombu/serialization.py" in dumps
340. return dumper(obj, protocol=pickle_protocol)

Exception Type: PicklingError at /contacts/upload/configurator/47/
Exception Value: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

表单.py

COL_CHOICES = [
('N/A', 'No Import'),
('first_name', 'First Name'),
('last_name', 'Last Name'),
('company', 'Company'),
('mobile', 'Mobile Number'),
('email', 'Email Address'),
]


class ConfiguratorForm(forms.Form):
col1 = forms.TypedChoiceField(choices=COL_CHOICES, initial='first_name')
col2 = forms.TypedChoiceField(choices=COL_CHOICES, initial='first_name')
col3 = forms.TypedChoiceField(choices=COL_CHOICES, initial='first_name')
col4 = forms.TypedChoiceField(choices=COL_CHOICES, initial='first_name')

最佳答案

您不提供您的 ConfiguratorForm 的定义,但无论如何:异步执行要求您的任务的参数是可选取的,而您的表单显然不是。你可能会走艰难的道路,让它变得可挑选,但这只是浪费时间。简单的解决方案是不传递表单,只传递表单的数据(iow:request.POST.copy() 但我不确定 Querydict 是否可以选择) - 或者更好,首先验证表单并只传递表单的 cleaned_data ,因为处理无效表单毫无意义。

关于python - 无法 pickle : attribute lookup builtin. 功能失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16091963/

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