How to use the pg8000.errors.InterfaceError function in pg8000

To help you get started, we’ve selected a few pg8000 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / core.py View on Github external
self._usock.connect((host, port))
            elif unix_sock is not None:
                self._usock.connect(unix_sock)

            if ssl:
                try:
                    self._lock.acquire()
                    import ssl as sslmodule
                    # Int32(8) - Message length, including self.
                    # Int32(80877103) - The SSL request code.
                    self._usock.sendall(ii_pack(8, 80877103))
                    resp = self._usock.recv(1)
                    if resp == b('S'):
                        self._usock = sslmodule.wrap_socket(self._usock)
                    else:
                        raise InterfaceError("Server refuses SSL")
                except ImportError:
                    raise InterfaceError(
                        "SSL required but ssl module not available in "
                        "this python installation")
                finally:
                    self._lock.release()

            # settimeout causes ssl failure, on windows.  Python bug 1462352.
            self._usock.settimeout(socket_timeout)
            self._sock = self._usock.makefile(mode="rwb")
        except socket.error:
            self._usock.close()
            raise InterfaceError("communication error", exc_info()[1])
        self._flush = self._sock.flush
        self._read = self._sock.read
github mfenniak / pg8000 / pg8000 / protocol.py View on Github external
def __init__(
            self, unix_sock=None, host=None, port=5432, socket_timeout=60,
            ssl=False):
        self._client_encoding = "ascii"
        self._integer_datetimes = False
        self._server_version = None
        self._sock_buf = ""
        self._sock_lock = threading.Lock()
        if unix_sock is None and host is not None:
            self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        elif unix_sock is not None:
            if not hasattr(socket, "AF_UNIX"):
                raise errors.InterfaceError(
                    "attempt to connect to unix socket on "
                    "unsupported platform")
            self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        else:
            raise errors.ProgrammingError(
                "one of host or unix_sock must be provided")
        if unix_sock is None and host is not None:
            self._sock.connect((host, port))
        elif unix_sock is not None:
            self._sock.connect(unix_sock)
        if ssl:
            self._sock_lock.acquire()
            try:
                self._flush_messages(SSLRequest().serialize())
                resp = self._sock.recv(1)
                if resp == 'S' and sslmodule is not None:
github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / core.py View on Github external
def execute(self, operation, args=None, stream=None):
        try:
            self._c._lock.acquire()
            self.stream = stream

            if not self._c.in_transaction and not self._c.autocommit:
                self._c.execute(self, "begin transaction", None)
            self._c.execute(self, operation, args)
        except AttributeError:
            if self._c is None:
                raise InterfaceError("Cursor closed")
            elif self._c._sock is None:
                raise InterfaceError("connection is closed")
            else:
                raise exc_info()[1]
        finally:
            self._c._lock.release()
github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / core.py View on Github external
    InterfaceError = property(lambda self: self._getError(InterfaceError))
    DatabaseError = property(lambda self: self._getError(DatabaseError))
github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / core.py View on Github external
# 705, the PG "unknown" type.
                val.extend(i_pack(705 if oid == -1 else oid))

            # Byte1('D') - Identifies the message as a describe command.
            # Int32 - Message length, including self.
            # Byte1 - 'S' for prepared statement, 'P' for portal.
            # String - The name of the item to describe.
            self._send_message(PARSE, val)
            self._send_message(DESCRIBE, STATEMENT + statement_name_bin)
            self._write(SYNC_MSG)

            try:
                self._flush()
            except AttributeError:
                if self._sock is None:
                    raise InterfaceError("connection is closed")
                else:
                    raise exc_info()[1]

            self.handle_messages(cursor)

            # We've got row_desc that allows us to identify what we're
            # going to get back from this statement.
            output_fc = tuple(
                self.pg_types[f['type_oid']][0] for f in ps['row_desc'])

            ps['input_funcs'] = tuple(f['func'] for f in ps['row_desc'])
            # Byte1('B') - Identifies the Bind command.
            # Int32 - Message length, including self.
            # String - Name of the destination portal.
            # String - Name of the source prepared statement.
            # Int16 - Number of parameter format codes.
github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / core.py View on Github external
def execute(self, operation, args=None, stream=None):
        try:
            self._c._lock.acquire()
            self.stream = stream

            if not self._c.in_transaction and not self._c.autocommit:
                self._c.execute(self, "begin transaction", None)
            self._c.execute(self, operation, args)
        except AttributeError:
            if self._c is None:
                raise InterfaceError("Cursor closed")
            elif self._c._sock is None:
                raise InterfaceError("connection is closed")
            else:
                raise exc_info()[1]
        finally:
            self._c._lock.release()
github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / __init__.py View on Github external
# For compatibility with 1.8
import pg8000 as dbapi
DBAPI = dbapi
pg8000_dbapi = DBAPI
from pg8000.core import utc

from pg8000.errors import (
    Warning, DatabaseError, InterfaceError,
    ProgrammingError, CopyQueryOrTableRequiredError, Error, OperationalError,
    IntegrityError, InternalError, NotSupportedError,
    ArrayContentNotHomogenousError, ArrayContentEmptyError,
    ArrayDimensionsNotConsistentError, ArrayContentNotSupportedError)

__all__ = [
    Warning, Bytea, DatabaseError, connect, InterfaceError, ProgrammingError,
    CopyQueryOrTableRequiredError, Error, OperationalError, IntegrityError,
    InternalError, NotSupportedError, ArrayContentNotHomogenousError,
    ArrayContentEmptyError, ArrayDimensionsNotConsistentError,
    ArrayContentNotSupportedError, utc]

from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
github mfenniak / pg8000 / pg8000 / protocol.py View on Github external
def _ok_error(self, msg):
        if msg.code == "28000":
            raise errors.InterfaceError("md5 password authentication failed")
        else:
            raise msg.createException()
github mfenniak / pg8000 / pg8000 / interface.py View on Github external
def read_dict(self):
        row = self._fetch()
        if row is None:
            return row
        retval = {}
        for i in range(len(self._row_desc.fields)):
            col_name = self._row_desc.fields[i]['name']
            if col_name in retval:
                raise InterfaceError(
                    "cannot return dict of row when two columns have the same "
                    "name (%r)" % (col_name,))
            retval[col_name] = row[i]
        return retval