Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

postgresql - Django + Psycopg2: InterfaceError: only protocol 3 supported

When loading pages in my Django + Postgresql setup I occasionally get this error but not all the time:

psycopg2 in connect

InterfaceError: only protocol 3 supported

psycopg2/__init__.py ? in connect

        raise TypeError('missing dsn and no parameters')
    else:
        dsn = " ".join(["%s=%s" % (k, _param_escape(str(v)))
            for (k, v) in items])
conn = _connect(dsn, connection_factory=connection_factory, async=async)
if cursor_factory is not None:
    conn.cursor_factory = cursor_factory
return conn

I have absolutely no idea what could be causing this.

My production.py settings file:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'mydbname',                      # Or path to database file if using sqlite3.
            # The following settings are not used with sqlite3:
            'USER': 'myuser',
            'PASSWORD': 'mypassword',
            'HOST': 'localhost',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
            'PORT': '',                      # Set to empty string for default.
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

http://initd.org/psycopg/docs/connection.html#connection.protocol_version

You didn't provide a version of postgres you are using.
Seems it's older than 7.4. In that case a solution will be to upgrade version of postgres
(or install older version of psycopg, but i think it's not good)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...