Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom api using extra_action gives error on POST request. #76

Open
abdulwahid24 opened this issue Jun 10, 2014 · 6 comments
Open

Custom api using extra_action gives error on POST request. #76

abdulwahid24 opened this issue Jun 10, 2014 · 6 comments

Comments

@abdulwahid24
Copy link

I have added custom api using extra_action such as
class Meta:
extra_actions = [
{
'name': 'login',
'http_method': 'POST',
'resource_type':'list',
'fields':{
'username': {
'type': 'string',
'required': True,
'description':'Unique username required.'
},
'password': {
'type': 'string',
'required': True,
'description':'password required'
}
}
}
]

This display the api in doc as mentioned in attached picture.
screenshot from 2014-06-10 17 00 33

But when i fill all mentioned fields and press "Try it Out" than it gives me error such as

{
"error_message": "The format indicated 'text/plain' had no available deserialization method. Please check your formats and content_types on your Serializer.",
"traceback": "Traceback (most recent call last):\n\n File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie/resources.py", line 195, in wrapper\n response = callback(request, _args, *_kwargs)\n\n File "/home/synerzip/Dropbox/Educator/educator-backend/educator/users/api.py", line 121, in login\n data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie/resources.py", line 375, in deserialize\n deserialized = self._meta.serializer.deserialize(data, format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie/serializers.py", line 219, in deserialize\n raise UnsupportedFormat("The format indicated '%s' had no available deserialization method. Please check your formats and content_types on your Serializer." % format)\n\nUnsupportedFormat: The format indicated 'text/plain' had no available deserialization method. Please check your formats and content_types on your Serializer.\n"
}
screenshot from 2014-06-10 16 35 15

Please refer the attached image.

Thanks,
AbdulWahid

@abdulwahid24 abdulwahid24 changed the title Custom api using extra_action give error on POST request. Custom api using extra_action gives error on POST request. Jun 10, 2014
@johnraz
Copy link
Contributor

johnraz commented Jun 10, 2014

This is an issue with the header format sent with your request.
I don't know of the top of my head why it is text/plain but it should be application/json.

@Seraf
Copy link

Seraf commented Jul 5, 2014

Hello,

Same problem here.

Request URL
/backend/api/v1/user/login/?username=seraf&password=XXXXXX&api_key=special-key

Response Body
{
"error_message": "The format indicated '' had no available deserialization method. Please check your formats and content_types on your Serializer.",
"traceback": "Traceback (most recent call last):\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 201, in wrapper\n response = callback(request, _args, *_kwargs)\n\n File "/home/julien/Sandbox/LISA/lisa/server/web/weblisa/api/accounts.py", line 124, in dispatch_login\n return self.dispatch_public('login', request, *_kwargs)\n\n File "/home/julien/Sandbox/LISA/lisa/server/web/weblisa/api/mixins.py", line 35, in dispatch_public\n response = method(request, *_kwargs)\n\n File "/home/julien/Sandbox/LISA/lisa/server/web/weblisa/api/accounts.py", line 127, in post_login\n data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 381, in deserialize\n deserialized = self._meta.serializer.deserialize(data, format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py", line 221, in deserialize\n raise UnsupportedFormat("The format indicated '%s' had no available deserialization method. Please check your formats and content_types on your Serializer." % format)\n\nUnsupportedFormat: The format indicated '' had no available deserialization method. Please check your formats and content_types on your Serializer.\n"
}

But, using POSTMAN application and sending the parameters using the application/json, it works. I suspect a bug with swagger (as the api works correctly on tastypie side).

I tried to print request.META.get('CONTENT_TYPE'). With postman I got "application/json", with swagger UI, got nothing. Hope it will help.

pombredanne pushed a commit to pombredanne/django-tastypie-swagger that referenced this issue Jul 8, 2014
@Seraf
Copy link

Seraf commented Sep 12, 2014

Hi, I think I found the problem.
The post parameters are sent in the query and not the body.
In the 1.2 specs, there's a paramType : https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524-parameter-object
I tried to set 'paramType': 'body' in my field but with no effect (with the last master). Maybe not implemented ?

@johnraz
Copy link
Contributor

johnraz commented Sep 12, 2014

Probably related to the swagger specs not being fully implemented. See here for a starting point.

@sanketsalunkhe
Copy link

i also got same error

my content type is application/json
still it not working

help me

@yusufcanb
Copy link

same issue with angularjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants