Ambiguous "500 - INTERNAL SERVER ERROR" error

22 views
Skip to first unread message

Huuuze

unread,
Jul 31, 2008, 10:52:55 AM7/31/08
to Django REST interface
I'm not sure if this problem is with the REST interface or with my
code. When I run the code below, the Django web server issues a "500
- INTERNAL SERVER ERROR" error. Any thoughts?

import urllib, urllib2

URL = 'http://localhost:8000/ws/person/'
XML = {'person': '<?xml version="1.0" encoding="utf-8"?><django-
objects version="1.0"><object pk="" model="persons.person"></object></
django-objects>'}

request = urllib2.Request(URL, urllib.urlencode(XML))
request.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.8.1.12)')
urllib2.urlopen(request)

Radu Brumariu

unread,
Jul 31, 2008, 11:28:34 AM7/31/08
to django-res...@googlegroups.com
you can print the return into an html file and see what Django said:

response = urllib2.urlopen(request)
f=open("log.html","w+")
f.write(response.read())
f.close()

Then open the file with your browser and see the detailed message.
Perhaps setting DEBUG=True in your Django instance( if not already )
would help troubleshoot.

HTH,
Radu

PS : my guess is that you are missing a value for the "pk" field, but
it is just a guess

Huuuze

unread,
Jul 31, 2008, 11:57:36 AM7/31/08
to Django REST interface
On Jul 31, 11:28 am, "Radu Brumariu" <bru...@gmail.com> wrote:
> you can print the return into an html file and see what Django said:
>
> response = urllib2.urlopen(request)
> f=open("log.html","w+")
> f.write(response.read())
> f.close()

In this instance, the "file" code won't execute; the exception is
generated by the call to urlopen().

>
> Then open the file with your browser and see the detailed message.
> Perhaps setting DEBUG=True in your Django instance( if not already )
> would help troubleshoot.

This code executes independent of Django. Its a client app that I
wrote to test out my connection to the Django REST Interface.

>
> HTH,
> Radu
>
> PS : my guess is that you are missing a value for the "pk" field, but
> it is just a guess
>

Since I'm only testing inserts (a.k.a., POSTs), I'm not sure how the
Django REST Interface handles new records. As such, I blanked out the
"pk" field since a new user should be issued a new ID based upon the
PK sequence.

Huuuze

unread,
Jul 31, 2008, 1:28:12 PM7/31/08
to Django REST interface
OK...found part of the problem. This call in model_resource.py is
throwing an error:

>> Line 143: self.receiver.get_post_data(request)

It generates an error with the following message:

>> <unknown>:1:5: not well-formed (invalid token)

At this point, I'm at a loss. You can see that I'm calling
"urllib.urlencode()", so the data should encoded. I also printed out
the request and examined the data in the POST:

POST:<QueryDict: {u'person': [u'<?xml version="1.0" encoding="utf-8"?
><django-objects version="1.0"><object pk="8" model="persons.person"></
object></django-objects>']}>,

Anyone feedback on what may be causing this problem?

Radu Brumariu

unread,
Jul 31, 2008, 1:30:29 PM7/31/08
to django-res...@googlegroups.com
The exception is server side, and the return will contain whatever
html your server has sent back. If you have debug set on your django
instance , your server will tell you where that exception happened.

Radu

Radu Brumariu

unread,
Jul 31, 2008, 1:32:16 PM7/31/08
to django-res...@googlegroups.com
The exception is server side, and the return will contain whatever
html your server has sent back. If you have debug set on your django
instance , your server will tell you where that exception happened.

Radu

On Thu, Jul 31, 2008 at 8:57 AM, Huuuze <huu...@orgoo.com> wrote:
>

Huuuze

unread,
Jul 31, 2008, 2:07:05 PM7/31/08
to Django REST interface
I figured it out. This call caused the 500 error:

>> urllib.urlencode(XML)

The REST interface didn't understand this request.POST value since it
was delivered as a key:value pair; the key in this instance was not
what the interface expected.

Alaa Salman

unread,
Jul 31, 2008, 4:26:09 PM7/31/08
to django-res...@googlegroups.com
Huuuze wrote:
> I figured it out. This call caused the 500 error:
>
>
>>> urllib.urlencode(XML)
>>>
>
> The REST interface didn't understand this request.POST value since it
> was delivered as a key:value pair; the key in this instance was not
> what the interface expected.
>
I am not sure if you have this solved, but what you are posting is not
well formed XML. Also, for the pk, i believe you need to put that as any
integer(i use 0), for the benefit of the deserializer, but don't worry
it will be neglected and the record given a new pk on insert.

--
Regards,
Alaa Salman
Entrepreneur, Contractor, Programmer
http://www.codedemigod.com
Free Software Foundation Associate Member #6304

"One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man." ---Elbert Hubbard
"Never measure the height of a mountain until you have reached the top. Then you will see how low it was." ---Dag Hammarskjold

Huuuze

unread,
Jul 31, 2008, 5:22:00 PM7/31/08
to Django REST interface
I have corrected the problem and I am now using the wonderful REST
API. Thank you very much for your help!


On Jul 31, 4:26 pm, Alaa Salman <alaasal...@gmail.com> wrote:
> Huuuze wrote:
> > I figured it out.  This call caused the 500 error:
>
> >>> urllib.urlencode(XML)
>
> > The REST interface didn't understand this request.POST value since it
> > was delivered as a key:value pair; the key in this instance was not
> > what the interface expected.
>
> I am not sure if you have this solved, but what you are posting is not
> well formed XML. Also, for the pk, i believe you need to put that as any
> integer(i use 0), for the benefit of the deserializer, but don't worry
> it will be neglected and the record given a new pk on insert.
>
> --
> Regards,
> Alaa Salman
> Entrepreneur, Contractor, Programmerhttp://www.codedemigod.com
Reply all
Reply to author
Forward
0 new messages