1

I'm using the following code in my server program:

class AddLibSong:
  def PUT(self):
  db = MahData.getDBConnection()
  songs = json.loads(web.input().to_add)
  addToLibrary(songs)
  return

But for some reason when I do a PUT with the data:

"to_add=[ { "album" : "Unknonwn", "artist" : "Unknonwn", "host_lib_id" : "1", "is_deleted" :
"false", "server_lib_id" : "-1", "song" : "Moneytalks" } ]" 

I get the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 237, in process
    return self.handle()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 228, in handle
    return self._delegate(fn, self.fvars, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 409, in _delegate
    return handle_class(cls)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 385, in handle_class
    return tocall(*args)
  File "/Users/kurtis/sandbox/udj/webserver/Library.py", line 114, in PUT
    song = json.loads(web.input().to_add)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/utils.py", line 76, in __getattr__
    raise AttributeError, k
AttributeError: 'to_add'

127.0.0.1:51096 - - [29/Sep/2011 19:02:58] "HTTP/1.1 PUT /add_songs_to_library" - 500 Internal Server Error

Anybody know why this is? I think I saw something about Web.py begin only able to get input if given a POST or GET but I didn't see anything in the source code that should prevent this.

3
  • Normally a REST service answering a PUT should say very little more than HTTP response code 200. In your case, the request is failing probably in response to some incorrect values; the JSON represents an array with one element, an object with keys and values. I hope this helps Commented Sep 30, 2011 at 0:39
  • So turns out I posted an incorrect error message. I have fixed this. You'll see the problem is with an AttributeError now. Commented Sep 30, 2011 at 3:49
  • 1
    Just tried changing this from a PUT to a POST, everything works now. Why can't I get the input on a PUT request? Commented Sep 30, 2011 at 4:38

1 Answer 1

1

Anyway, if you want more details on how to use PUT with WebPy I would advice you this great link.

To make it work on the last version of webpy you should change the "main" code to that:

if __name__ == "__main__":

    app=web.application(urls, globals())
    app.run()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.