Reputation: 32959
What i trying to do is setup a simple custom Resource
, something as follows:
MailResource(Resource):
to = fields.CharField(attribute='To')
subject = fields.CharField(attribute='Subject')
message = fields.CharField(attribute='Message')
class Meta:
resource_name = 'mail'
allowed_methods = ['post']
authorization = Authorization()
def detail_uri_kwargs(self, bundle_or_obj):
kwargs = {}
if isinstance(bundle_or_obj, Bundle):
kwargs['pk'] = bundle_or_obj.obj.uuid
else:
kwargs['pk'] = bundle_or_obj.uuid
return kwargs
def obj_create(self, bundle, request=None, **kwargs):
print bundle.obj
print request
print kwargs
# Create the object
return bundle
But when i make a test post request using curl, i always get 401 UNAUTHORIZED error. why so ? Isn't Authorization()
class is meant to return true for is_authorized
method. The documentation says Authorization()
is :
The no-op authorization option, no permissions checks are performed.
then why is it failing ?
I also tried a custom authorization class which always return True
in the is_authorized
method no matter what, but it still raises 401 UNAUTHORIZED error. Any Clues?
Upvotes: 1
Views: 2780
Reputation: 9568
I have been facing the same issue. Looks like SessionAuthentication is not supposed to work with HTTP POST.
Have explained more here
Does SessionAuthentication work in Tastypie for HTTP POST?
Upvotes: 2