django-tastypie 和 django-tastypie-mongoengine PATCH 错误
django-tastypie and django-tastypie-mongoengine PATCH error
尝试通过 python requests
以及命令行 cURL 提交 PATCH 请求,我收到以下响应:
>>> r = requests.patch(url)
>>> r.text
u'{"error_message": "PATCH",
"traceback": "Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tastypie/resources.py", line 201, in wrapper
response = callback(request, *args, **kwargs)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tastypie/resources.py", line 441, in dispatch_detail
return self.dispatch('detail', request, **kwargs)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_tastypie_mongoengine-0.4.5-py2.7.egg/tastypie_mongoengine/resources.py", line 385, in dispatch
assert request.method.lower() not in ('put', 'post', 'patch'), request.method
AssertionError: PATCH"}'
>>> r.request.method.lower()
'patch'
>>>
不确定我是否遗漏了什么,但看起来 PATCH 方法在列表中并且断言不应触发。它甚至还不足以验证 'patch' 是资源的允许方法,它是:
allowed_methods = ('get', 'post', 'patch')
更新:POST 引起了同样的问题!此代码在一两周前对 POST 运行良好,并且未对其进行任何更改。最近唯一改变的东西(OSX 笔记本电脑)是最新一轮的 OS 补丁。我还注意到这个 github 问题,我已回复:https://github.com/wlanslovenija/django-tastypie-mongoengine/issues/91。不确定这是否是同一个问题(POST 应该允许请求正文,所以我不知道)。
原来主要问题是 POST 和 PATCH 都需要在正文中传递一些数据,而其他需要在 URL 参数中传递。
尝试通过 python requests
以及命令行 cURL 提交 PATCH 请求,我收到以下响应:
>>> r = requests.patch(url)
>>> r.text
u'{"error_message": "PATCH",
"traceback": "Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tastypie/resources.py", line 201, in wrapper
response = callback(request, *args, **kwargs)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tastypie/resources.py", line 441, in dispatch_detail
return self.dispatch('detail', request, **kwargs)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_tastypie_mongoengine-0.4.5-py2.7.egg/tastypie_mongoengine/resources.py", line 385, in dispatch
assert request.method.lower() not in ('put', 'post', 'patch'), request.method
AssertionError: PATCH"}'
>>> r.request.method.lower()
'patch'
>>>
不确定我是否遗漏了什么,但看起来 PATCH 方法在列表中并且断言不应触发。它甚至还不足以验证 'patch' 是资源的允许方法,它是:
allowed_methods = ('get', 'post', 'patch')
更新:POST 引起了同样的问题!此代码在一两周前对 POST 运行良好,并且未对其进行任何更改。最近唯一改变的东西(OSX 笔记本电脑)是最新一轮的 OS 补丁。我还注意到这个 github 问题,我已回复:https://github.com/wlanslovenija/django-tastypie-mongoengine/issues/91。不确定这是否是同一个问题(POST 应该允许请求正文,所以我不知道)。
原来主要问题是 POST 和 PATCH 都需要在正文中传递一些数据,而其他需要在 URL 参数中传递。