我正在研究Udacity的在线项目.我正在使用vagrant
他们配置,运行包含数据库的服务器.不幸的是,当我试图给出代码持久性时,服务器每次都会返回一个错误.我是python的新手所以请原谅任何明显的错误.
这是错误:
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
这是我在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 - 此文件呈现html从数据库中提取数据:http://pastebin.com/ZiHWiiwr
请帮忙 !