Re: ValueError: No JSON object could be decoded

2015-06-22 Thread Bill Freeman
You probably don't want request.body.  You are probably POSTing the JSON
using a form, which means that it shows up as something like
request.POST['data'], where you should replace 'data' with the name of the
form element (textarea?) where you are putting the JSON.  Posting with a
form wraps things up in a multipart form (allowing you to have, among other
things, more than one field in a post), and that extra stuff doesn't look
line JSON, but the whole is what you get when you use request.body.

On Sun, Jun 21, 2015 at 11:13 AM, Vijay Khemlani <vkhem...@gmail.com> wrote:

> What is the actual content of request.body? (as in, "print request.body")
>
> On Sun, Jun 21, 2015 at 9:26 AM, Dhaval M <dhaval0...@gmail.com> wrote:
>
>> Thank you in advance for any help (this is my first post to this
>> community)
>>
>> I am using Django as my application server for my project. I am new to
>> web development so please pardon and feel free to correct me for any
>> mistake.
>>
>> I am running simple, client server combination where from client I am
>> trying to send JSON data and on the server I am trying to parse it.
>>
>> SERVER CODE:
>>
>> def addPatient(request):
>>
>>  if request.method == 'POST':
>>
>> # Convert JSON to python objects and
>>
>> # store into the DB
>>
>> recJSON = json.loads(request.body)
>>
>> #logger.debug("%s",recJSON['SenderID'])
>>
>> logger.debug("%s",request.body)
>>
>>
>> #print 'Raw Json "%s"' % request.body
>>
>> return HttpResponse(json.dumps(request.body),content_type=
>> "application/json")
>>
>>
>>
>>
>> But getting an error at json.loads. ValueError: No JSON object could be
>> decoded
>>
>>
>> Also I would appreciate if any one can direct me to good tutorial on
>> Django (I already read http://www.djangobook.com/)
>>
>>
>> I dont know where and what I am doing wrong. I checked the client side
>> message and it is JSON used http://jsonlint.com/ to validate it is JSON
>> data.
>>
>>
>> Thank you once again.
>>
>> --
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/5bc51870-6b56-456f-bc6d-18cf20487265%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/5bc51870-6b56-456f-bc6d-18cf20487265%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALn3ei1Sdb_QGG3hxixj2RNqiqaafjQMkwqGkpokXqcCOGgejA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALn3ei1Sdb_QGG3hxixj2RNqiqaafjQMkwqGkpokXqcCOGgejA%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0sUoKrU%2BGYBij8hnbMNkggdJFUBsYm9GNvZ%3D3nUc89B0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: No JSON object could be decoded

2015-06-21 Thread Vijay Khemlani
What is the actual content of request.body? (as in, "print request.body")

On Sun, Jun 21, 2015 at 9:26 AM, Dhaval M <dhaval0...@gmail.com> wrote:

> Thank you in advance for any help (this is my first post to this community)
>
> I am using Django as my application server for my project. I am new to web
> development so please pardon and feel free to correct me for any mistake.
>
> I am running simple, client server combination where from client I am
> trying to send JSON data and on the server I am trying to parse it.
>
> SERVER CODE:
>
> def addPatient(request):
>
>  if request.method == 'POST':
>
> # Convert JSON to python objects and
>
> # store into the DB
>
> recJSON = json.loads(request.body)
>
> #logger.debug("%s",recJSON['SenderID'])
>
> logger.debug("%s",request.body)
>
>
> #print 'Raw Json "%s"' % request.body
>
>     return HttpResponse(json.dumps(request.body),content_type=
> "application/json")
>
>
>
>
> But getting an error at json.loads. ValueError: No JSON object could be
> decoded
>
>
> Also I would appreciate if any one can direct me to good tutorial on
> Django (I already read http://www.djangobook.com/)
>
>
> I dont know where and what I am doing wrong. I checked the client side
> message and it is JSON used http://jsonlint.com/ to validate it is JSON
> data.
>
>
> Thank you once again.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5bc51870-6b56-456f-bc6d-18cf20487265%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5bc51870-6b56-456f-bc6d-18cf20487265%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1Sdb_QGG3hxixj2RNqiqaafjQMkwqGkpokXqcCOGgejA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


ValueError: No JSON object could be decoded

2015-06-21 Thread Dhaval M
Thank you in advance for any help (this is my first post to this community)

I am using Django as my application server for my project. I am new to web 
development so please pardon and feel free to correct me for any mistake.

I am running simple, client server combination where from client I am 
trying to send JSON data and on the server I am trying to parse it.

SERVER CODE:

def addPatient(request):

 if request.method == 'POST':

# Convert JSON to python objects and

# store into the DB

recJSON = json.loads(request.body)

#logger.debug("%s",recJSON['SenderID'])

logger.debug("%s",request.body)


#print 'Raw Json "%s"' % request.body

return HttpResponse(json.dumps(request.body),content_type=
"application/json")

    


But getting an error at json.loads. ValueError: No JSON object could be 
decoded 


Also I would appreciate if any one can direct me to good tutorial on Django 
(I already read http://www.djangobook.com/)


I dont know where and what I am doing wrong. I checked the client side 
message and it is JSON used http://jsonlint.com/ to validate it is JSON 
data.


Thank you once again.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5bc51870-6b56-456f-bc6d-18cf20487265%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.