I am working on an online project by Udacity. I am using vagrant
configured by them, to run the server containing the Database. Unfortunately when I tried to give the code persistence, the server returns an error everytime. I am new to python so please forgive any obvious mistakes.
Here is the error :
Serving HTTP on port 8000...
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "forum.py", line 95, in Dispatcher
return DISPATCH[page](env, resp)
File "forum.py", line 68, in Post
length = int(env.get('CONTENT_LENGTH', 0))
ValueError: invalid literal for int() with base 10: ''
10.0.2.2 - - [06/Jan/2016 04:44:16] "GET /post HTTP/1.1" 500 59
10.0.2.2 - - [06/Jan/2016 04:44:16] "GET /favicon.ico HTTP/1.1" 404 22
And this is the code that I have changed in forumdb.py :
#
# Database access functions for the web forum.
#
import psycopg2
## Database connection
def GetAllPosts():
DB = psycopg2.connect("dbname=forum")
c = DB.cursor()
c.execute("SELECT time, content FROM posts ORDER BY time DESC")
posts = ({'content': str(row[1]), 'time': str(row[0])}
for row in c.fetchall())
# This returns a dictionary -- returning just c.fetchall() will return a list of tuples
DB.close()
return posts
def AddPost(content):
DB = psycopg2.connect("dbname=forum")
c = DB.cursor()
c.execute("INSERT INTO posts (content) values ('%s')" % content)
DB.commit()
DB.close()
forum.py - this file renders the html bringing data from the DB : http://pastebin.com/ZiHWiiwr
Please help !