On Sep 2, 9:57 am, irum <irumrauf...@gmail.com> wrote: > Hi, > I am having problems with extracting json data for parsing from HTTP > GET request. > > What I am doing is that I am receiving json data over HTTP via GET. > After debugging much, I have realized that the data also has HTTP > headers and other information that serializer is not able to > deserialize. How can I extract json data from the complete data > (including HTTP information)? > > This is the data I receive, i.e. p, and I want to extract json from it > and deserialize it for parsing. > > HTTP/1.0 200 OK Date: Thu, 02 Sep 2010 08:37:39 GMT Server: WSGIServer/ > 0.1 Python/2.6.4 Content-Type: application/json [{"pk": 33, "model": > "hbexample.payment", "fields": {"confirm": true, "pDate": "2010-08-31 > 10:42:19", "waiting": false, "amount": 33.0, "p_try": 0, "booking": > 34}}] > > I have tried json.loads and json.dumps on this data. > > With json.loads(p), I get the following error: expected string or > buffer > > With json.dumps(p), I get the following error: > <django.http.HttpResponse object at 0x150da50> is not JSON > serializable > > How do I address this problem? Any help regarding this would be > helpful. > > Thanks and Looking forward, > Irum
json.loads() and dujmps() work on a string or string-like object. HttpResponse is a file-like object, not a string, so you could either do loads(p.read()), or - much better - use the load() and dump() methods, without the s, directly on the HttpResponse. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.