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 <pratikmandrekar@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 HttpURLConnectionurlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);urlConnection.setDoOutput(true);urlConnection.setRequestProperty("Content-Type", "application/json");byte [] encoded = Base64.encode((username+":"+password).getBytes("UTF-8"), Base64.DEFAULT);urlConnection.setRequestProperty("Authorization", "Basic "+ new String(encoded, "UTF-8"));JSONObject jsonObject = new JSONObject();jsonObject.put("key1", "value1");jsonObject.put("key2", "value2");outputStreamWriter = urlConnection.getOutputStream();outputStreamWriter.write(jsonObject.toString().getBytes());outputStreamWriter.flush();And I have tried with Apache HttpClientHttpClient 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",jsonObject.toString()));lotlisting.setEntity(new UrlEncodedFormEntity(localArrayList));String str = EntityUtils.toString(localDefaultHttpClient.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.To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.Pratik--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@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+unsubscribe@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+unsubscribe@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.
No comments:
Post a Comment