'选项'对象没有属性' module_name'

时间:2015-02-23 22:22:46

标签: python django tastypie

Django 1.8a1
Tastypie 0.12.0

我想通过api修补我的对象

当我尝试卷曲api时:

 
➜  sesame git:(migration) ✗ curl --dump-header -b cookies -v -H "X-CSRFToken: 5HA6yUXRtdf6KsHK6V52GKm1WkGWuvLh"  -H "Content-Type: application/json" -X PATCH --data '{"login": "111"}' http://127.0.0.1:8000/api/v1/serviceAccountEmail/50D2CB33-1ED8-4925-B542-9CE26C961C09/

我收到了错误:


* Rebuilt URL to: cookies/
* Hostname was NOT found in DNS cache
* Could not resolve host: cookies
* Closing connection 0
curl: (6) Could not resolve host: cookies
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#1)
> PATCH /api/v1/serviceAccountEmail/50D2CB33-1ED8-4925-B542-9CE26C961C09/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8000
> Accept: */*
> X-CSRFToken: 5HA6yUXRtdf6KsHK6V52GKm1WkGWuvLh
> Content-Type: application/json
> Content-Length: 16
> 
* upload completely sent off: 16 out of 16 bytes
* HTTP 1.0, assume close after body
 HTTP/1.0 500 INTERNAL SERVER ERROR
 Date: Mon, 23 Feb 2015 21:56:48 GMT
 Server: WSGIServer/0.1 Python/2.7.6
 X-Frame-Options: SAMEORIGIN
 Content-Type: application/json

{"error_message": "'Options' object has no attribute 'module_name'", "traceback": "Traceback (most recent call last):\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 204, in wrapper\n    response = callback(request, *args, **kwargs)\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 444, in dispatch_detail\n    return self.dispatch('detail', request, **kwargs)\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 467, in dispatch\n    response = method(request, **kwargs)\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 1626, in patch_detail\n    self.update_in_place(request, bundle, deserialized)\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 1649, in update_in_place\n    return self.obj_update(bundle=original_bundle, **kwargs)\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 2167, in obj_update\n    return self.save(bundle, skip_errors=skip_errors)\n\n  File \"/home/andrey/repos/sesame/tastypie/resou* Closing connection 1
rces.py\", line 2245, in save\n    self.authorized_update_detail(self.get_object_list(bundle.request), bundle)\n\n  File \"/home/andrey/repos/sesame/tastypie/resources.py\", line 650, in authorized_update_detail\n    auth_result = self._meta.authorization.update_detail(object_list, bundle)\n\n  File \"/home/andrey/repos/sesame/tastypie/authorization.py\", line 214, in update_detail\n    permission = '%s.change_%s' % (klass._meta.app_label, klass._meta.module_name)\n\nAttributeError: 'Options' object has no attribute 'module_name'\n"}%  

Google无法帮助我解决这种情况

1 个答案:

答案 0 :(得分:-1)

您需要更改curl选项:

根据docs

-b, --cookie <name=data>
  

(HTTP)将数据作为cookie传递给HTTP服务器。据说是   先前从“Set-Cookie:”行中的服务器接收的数据。   数据格式应为“NAME1 = VALUE1; NAME2 = VALUE2”。

     

如果行中没有使用'='符号,则将其视为文件名   用于读取以前存储的cookie行,应该使用它们   在这个会话中,如果他们匹配。使用此方法也可以激活   “cookie解析器”,它将使curl记录传入的cookie,   如果你将它与-L结合使用可能会很方便,    - 位置选项。从中读取cookie的文件的文件格式应该是纯HTTP标头或Netscape / Mozilla cookie文件   格式。

     

使用-b, - coolie指定的文件仅用作输入。没有饼干   将被写入文件。要存储cookie,请使用-c,   --cookie-jar选项。

     

如果多次使用此选项,将使用最后一个选项。