Hi,
Thanks for your prompt reply.
I have tried both the things but I get the same error.
With,
x = json.loads(p.read())
           print x

I get following error:  'HttpResponse' object has no attribute
'read'
Also I get same error with, json.dumps(p.read()), and same when I use
loads and dumps as load and dump without s.

Then, I tried the other option,

x = json.dump(p)
        print x

I get the following error: dump() takes at least 2 arguments (1 given)
What would be the second argument, I googled on this but find no
helpful tips as everything written is too complicated.

And with:
           x = json.load(p)
           print x

'HttpResponse' object has no attribute 'read'

In all the examples, p is the HttpResponse object I get.

Looking forward,
Irum




On Sep 2, 12:09 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> 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.

Reply via email to