Still, if you have a break point where the request comes in to the view,
you can inspect the POST data to see how it differs from what you expect.
That might inform you as to what you might do differently in your
JavaScript, whether you need some additional or different encoding or
quoting of the data, whether you need to be more explicit about the
content-type header (you may have to look at the WSGI request object
itself), etc.  Or you may discover that you need to breakpoint at the WSGI
application script level to see what you need to see.

Since nobody has jumped in with "I recognize that problem", inspecting your
data is probably a good use of your time.  pdb is not hard to use, as long
as you are using runserver (and you can almost always arrange to explore a
problem under runserver) because there has to be a console for pdb to type
on, and on which you can type commands.  The first breakpoint is the only
django specific trick.  Put

    import pdb; pdb.set_trace()

where you want to stop.  You can use the b command to set additional
breakpoints later, but that can be confusing due to threading.  pdb is
documented in the library reference for your python version at python.org.
Read up on the p, pp, u, d, c, n, s, r, !, and q, commands, probably in
that order, and you will find that you usually only use the first 5 of
them.  (There are more, for when you want to be a pdb expert.)  And
remember to start with a p or pp when you want to see the value of an
expression, lest your expression be interpreted as one of the other
commands.

Bill

On Sat, Mar 23, 2013 at 5:19 AM, Pratik Mandrekar <pratikmandre...@gmail.com
> wrote:

> The issue is with setting data in the http post request. I have tried it
> with curl and the web client and it works. CSRF is not the issue, requests
> work fine without the csrftoken outside of the android client.
>
> Pratik
>
>
>
> On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>
>> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>>
>> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar 
>> <pratikm...@gmail.com>wrote:
>>
>>> Hello,
>>>
>>> I'm unable to get the POST json to tastypie from an android http client
>>> to work.
>>>
>>> *I have tried with HttpURLConnection*
>>>
>>> urlConnection = (HttpURLConnection) url.openConnection();
>>>
>>>
>>> urlConnection.setDoInput(true)****;
>>>
>>> urlConnection.setDoOutput(**true**);
>>>
>>>  urlConnection.**setRequestProper**ty("Content-**Type",
>>> "application/json");
>>>
>>> byte [] encoded = 
>>> Base64.encode((username+":"+**pa**ssword).getBytes("UTF-8"),
>>> Base64.DEFAULT);
>>>
>>> urlConnection.**setRequestProper**ty("**Authorization", "Basic "+ new
>>> String(encoded, "UTF-8"));
>>>
>>>
>>> JSONObject jsonObject = new JSONObject();
>>>
>>> jsonObject.put("key1", "value1");
>>>
>>> jsonObject.put("key2", "value2");
>>>
>>>   outputStreamWriter = urlConnection.getOutputStream(****);
>>>
>>>  outputStreamWriter.write(**jsonO**bject.toString().**getBytes());
>>>
>>>  outputStreamWriter.flush();
>>>
>>>
>>>
>>>
>>> *And I have tried with Apache HttpClient*
>>>
>>> HttpClient client=new DefaultHttpClient();
>>>
>>> HttpPost post = new HttpPost(url);
>>>
>>>
>>>
>>> post.setHeader("accept", "application/json");
>>>
>>> post.addHeader("Content-Type", "application/json");
>>>
>>> post.addHeader("Authorization"****, "Basic "+ new String(encoded,
>>> "UTF-8"));
>>>
>>>
>>>
>>> ArrayList localArrayList = new ArrayList();
>>>
>>> localArrayList.add(new BasicNameValuePair("json",**json**
>>> Object.toString()));
>>>
>>>
>>>
>>>  lotlisting.setEntity(new UrlEncodedFormEntity(**localArra**yList));
>>>
>>>  String str = EntityUtils.toString(**localDefa**ultHttpClient.**execute(
>>> **lotlisting).getEntity(**));
>>>
>>>
>>> StringEntity se = new StringEntity( jsonObject.toString());
>>>
>>> se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
>>> "application/json"));
>>>
>>>
>>>
>>>  post.setEntity(se);
>>>
>>>
>>>
>>>  HttpResponse response = client.execute(post);
>>>
>>>
>>> I hit the same issue with both of them i.e the POST data as seen as
>>> Querydict in Django, does not have any data. This makes it an invalid json
>>> and it throws a JSON could not be decoded error.
>>>
>>> I have tried playing with all the parameters with little luck. Note that
>>> *get works perfectly*, even with parameters.
>>>
>>> Has anyone been successfully able to post json from an android client to
>>> django/tastypie? If yes, could you please share what worked for you?
>>>
>>> Thanks.
>>>
>>> Pratik
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to