我正在拉我的頭髮,並準備好做一些骯髒的事情。class'psycopg2.InterfaceError':連接已關閉
我正在運行nginx + django + postgresql。半我想測試我的網站,打開頁面的時候,我得到如下:
<class 'psycopg2.InterfaceError'> Python 2.7.2: /home/webapp/newavenue/bin/python
Fri Feb 24 08:28:58 2012
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/home/webapp/newavenue/lib/python2.7/site-packages/flup/server/fcgi_base.py in run(self=<flup.server.fcgi_base.Request object>)
572
573 try:
=> 574 protocolStatus, appStatus = self.server.handler(self)
575 except:
576 traceback.print_exc(file=self.stderr)
protocolStatus undefined, appStatus undefined, self = <flup.server.fcgi_base.Request object>, self.server = <flup.server.fcgi_fork.WSGIServer object>, self.server.handler = <bound method WSGIServer.handler of <flup.server.fcgi_fork.WSGIServer object>>
/home/webapp/newavenue/lib/python2.7/site-packages/flup/server/fcgi_base.py in handler(self=<flup.server.fcgi_fork.WSGIServer object>, req=<flup.server.fcgi_base.Request object>)
1157 try:
1158 try:
=> 1159 result = self.application(environ, start_response)
1160 try:
1161 for data in result:
result = None, self = <flup.server.fcgi_fork.WSGIServer object>, self.application = <django.core.handlers.wsgi.WSGIHandler object>, environ = {'CONTENT_LENGTH': '', 'CONTENT_TYPE': '', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', 'HTTP_CACHE_CONTROL': 'max-age=0', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'csrftoken=8a0176b368b17af00a8563b5f95b134b; sess...e5bdd0d0a4e3092e7a9abd0029c02; django_language=en', 'HTTP_HOST': 'newavedev.zapto.org', ...}, start_response = <function start_response>
/home/webapp/newavenue/lib/python2.7/site-packages/django/core/handlers/wsgi.py in __call__(self=<django.core.handlers.wsgi.WSGIHandler object>, environ={'CONTENT_LENGTH': '', 'CONTENT_TYPE': '', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', 'HTTP_CACHE_CONTROL': 'max-age=0', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'csrftoken=8a0176b368b17af00a8563b5f95b134b; sess...e5bdd0d0a4e3092e7a9abd0029c02; django_language=en', 'HTTP_HOST': 'newavedev.zapto.org', ...}, start_response=<function start_response>)
272 response = self.get_response(request)
273 finally:
=> 274 signals.request_finished.send(sender=self.__class__)
275
276 try:
global signals = <module 'django.core.signals' from '/home/webapp...python2.7/site-packages/django/core/signals.pyc'>, signals.request_finished = <django.dispatch.dispatcher.Signal object>, signals.request_finished.send = <bound method Signal.send of <django.dispatch.dispatcher.Signal object>>, sender undefined, self = <django.core.handlers.wsgi.WSGIHandler object>, self.__class__ = <class 'django.core.handlers.wsgi.WSGIHandler'>
/home/webapp/newavenue/lib/python2.7/site-packages/django/dispatch/dispatcher.py in send(self=<django.dispatch.dispatcher.Signal object>, sender=<class 'django.core.handlers.wsgi.WSGIHandler'>, **named={})
170
171 for receiver in self._live_receivers(_make_id(sender)):
=> 172 response = receiver(signal=self, sender=sender, **named)
173 responses.append((receiver, response))
174 return responses
response undefined, receiver = <function close_connection>, signal undefined, self = <django.dispatch.dispatcher.Signal object>, sender = <class 'django.core.handlers.wsgi.WSGIHandler'>, named = {}
/home/webapp/newavenue/lib/python2.7/site-packages/django/db/__init__.py in close_connection(**kwargs={'sender': <class 'django.core.handlers.wsgi.WSGIHandler'>, 'signal': <django.dispatch.dispatcher.Signal object>})
83 def close_connection(**kwargs):
84 for conn in connections.all():
=> 85 conn.close()
86 signals.request_finished.connect(close_connection)
87
conn = <django.db.backends.postgresql_psycopg2.base.DatabaseWrapper object>, conn.close = <bound method DatabaseWrapper.close of <django.d...postgresql_psycopg2.base.DatabaseWrapper object>>
/home/webapp/newavenue/lib/python2.7/site-packages/django/db/backends/__init__.py in close(self=<django.db.backends.postgresql_psycopg2.base.DatabaseWrapper object>)
242 def close(self):
243 if self.connection is not None:
=> 244 self.connection.close()
245 self.connection = None
246
self = <django.db.backends.postgresql_psycopg2.base.DatabaseWrapper object>, self.connection = <connection object at 0x1d37130; dsn: 'dbname=ne...er=postgres host=localhost port=5432', closed: 2>, self.connection.close = <built-in method close of psycopg2._psycopg.connection object>
<class 'psycopg2.InterfaceError'>: connection already closed
args = ('connection already closed',)
cursor = None
message = 'connection already closed'
pgcode = None
pgerror = None
服務器運行具有以下生成前面flup追蹤報告:
python manage.py runfcgi host=127.0.0.1 port=8000 debug=False
莫非
我只是通過修補類似於「try:self.connection.close()」來解決此問題,除了:繞過那條違規行嗎?它可能會工作,但我認爲這聽起來很髒(與核心混亂),我想嘗試找到一種替代解決方案。
編輯:考慮到這傢伙的做法太:註釋掉它:http://osdir.com/ml/DjangoUsers/2009-04/msg01647.html
前段時間我有一個類似的錯誤,不記得它是否是同一件事,但問題是新版本的psycopg被釋放並且不兼容。嘗試降級psycopg。如果這是不可能的,試試django 1.4beta或者可能只是1.4beta的pg db模塊。 – 2012-02-24 13:11:36