Sto lavorando a un progetto online Udacity. Sto usando vagrant
configurato da loro, per eseguire il server che contiene il Database. Sfortunatamente quando ho provato a dare la persistenza del codice, il server restituisce un errore ogni volta. Sono nuovo di Python quindi per favore perdona qualsiasi errore evidente.DB Pyscopg - Errore di aggiunta di persistenza al codice
Ecco l'errore:
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
E questo è il codice che ho cambiato 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 - questo file rende l'html portando i dati dal DB: http://pastebin.com/ZiHWiiwr
Si prega di aiuto!
Grazie per la spiegazione! Errore amatoriale .. Ma grazie ancora una volta! –