Re: content_type in Client() post doesn't correctly encode
On Sun, Oct 14, 2012 at 1:48 PM, Christopher Hartfield
<chris@mxmtech.net> wrote:
> I think I may have a bug in the client test class in the post method.
> Normally you can call:
> url_data = {'something': 'something'}
> response = c.post(ip, url_data, content_type='application/xml')
>
> When I do this I get a 401 response and this data:
> Content-Type: text/html; charset=utf-8
>
> That's it. I don't get any actual data. If I remove the content_type
> argument the problem goes away (but I have the default content type which I
> don't want
>
> I have come across this problem because I am testing an api and it requires
> the content-type to be application/xml.
>
> How do I specify content_type correctly in Django's testing client with post
> data?
The problem isn't the content type definition -- it's what your own
code is doing with the request.
A 401 response indicates that your own render() line isn't being
executed -- you're being bounced for a failed authentication. For some
reason, the client request isn't providing the expected authentication
credentials (either the HTTP_AUTHORIZATION header if you're using HTTP
Basic auth, or the session if you're using a login-based auth, or
possibly something else), and as a result, the client request is being
rejected.
I'm a little confused as to why dropping the content type argument
would alter the outcome, but this must be something to do with your
own code. Django itself doesn't have any 401 (to the extent that there
isn't even a 401 response type defined by default), so the code
raising the 401 isn't anything on Django's side.
Yours,
Russ Magee %-)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home