I'd recommend trying psycopg2 as the driver as it may handle this failure mode more gracefully.


On 08/02/2016 04:34 AM, Simon King wrote:
It looks like an exception is occurring, which SQLAlchemy has caught
and is now trying to roll back the transaction before re-raising the
initial exception. However, a second exception has occurred during the
rollback, so you can no longer see the original exception.

The second exception looks like a possible bug in the pg8000 driver,
where it's trying to send a rollback command without an actual
connection to the database.

In order to find the original exception, perhaps you could start by
putting some print statements in the _handle_dbapi_exception method:

https://bitbucket.org/zzzeek/sqlalchemy/src/3873d7db340835a38e6b191e8466fb42c3a9d3f6/lib/sqlalchemy/engine/base.py?at=master&fileviewer=file-view-default#base.py-1235

Hope that helps,

Simon

On Tue, Aug 2, 2016 at 4:11 AM, Nikhil S Menon <nikhilsme...@gmail.com> wrote:
If the datatype of in database is Varchar its working fine, error comes only
with integer. Any help here is highly appreciated.

Best Regards,
Nikhil


On Sunday, 31 July 2016 22:28:27 UTC+5:30, Nikhil S Menon wrote:

i am using SQLAlchemy-1.0.5.


i have an external db with a table having integer. while i run the select
query i am getting below error.

File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 914, in execute
    return meth(self, multiparams, params)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py",
line 323, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1010, in _execute_clauseelement
    compiled_sql, distilled_params
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1146, in _execute_context
    context)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1334, in _handle_dbapi_exception
    self._autorollback()
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 791, in _autorollback
    self._root._rollback_impl()
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 670, in _rollback_impl
    self._handle_dbapi_exception(e, None, None, None, None)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1266, in _handle_dbapi_exception
    exc_info
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py",
line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 668, in _rollback_impl
    self.engine.dialect.do_rollback(self.connection)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py",
line 420, in do_rollback
    dbapi_connection.rollback()
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/pg8000/core.py", line
1751, in rollback
    self.execute(self._cursor, "rollback", None)
  File
"/home/nfs/nikhil/local/lib/python2.7/site-packages/pg8000/core.py", line
2016, in execute
    self._flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
sqlalchemy.exc.DBAPIError: (exceptions.AttributeError) 'NoneType' object
has no attribute 'sendall'
No handlers could be found for logger "sqlalchemy.pool.QueuePool"


sqlalchemy.exc.DBAPIError: (exceptions.AttributeError) 'NoneType' object
has no attribute 'sendall'


from sqlalchemy import *
def connect_db(db):

engine=create_engine('postgresql+pg8000://postgres@10.102.31.123:5432/%s'%db)
    return engine

def load_table(table_name):
    table_data = Table(table_name, m, autoload=True, autoload_with=engine)
    return table_data

def get_all_tables_data():
    m.reflect(bind=engine)
    for table in m.tables:
        print "%s\n---------\n"%table
        table_data = load_table(table)
        q = select([table_data])
        print q
        res = conn.execute(q)
        for row in res:
            print row
engine = connect_db("db")
m = MetaData(engine)
conn = engine.connect()
get_all_tables_data()


Its happening with external database only when I use the sqlalchemy
library in python.  If i use postgres shell its working. Please find below
details from postgres interface.

db=# \d mas_license;
           Table "public.mas_license"
     Column     |       Type        | Modifiers
----------------+-------------------+-----------
 id             | character varying | not null
 node_id        | character varying |
 rpt_sampletime | bigint            |
 max_vips       | character varying |
 pooled_lic     | integer           |
 cpx_lic        | integer           |
 perf           | integer           |
 snmp_traps     | integer           |
 syslog         | integer           |
 analytics      | integer           |
 adv_analytics  | integer           |
Indexes:
    "mas_license_pkey" PRIMARY KEY, btree (id)

=# select * from mas_license;
                  id                  | node_id | rpt_sampletime |
max_vips                             | pooled_lic | cpx_lic | perf |
snmp_traps | syslog | analytics | adv_analytics

--------------------------------------+---------+----------------+------------------------------------------------------------------+------------+---------+------+------------+--------+-----------+---------------
 5-34 |         |     1469625865 | f6f6-34437c |          1 |       1 |
3 |          3 |      3 |         3 |             1
(1 row)

Using pgxl as external database.


Best Regards,
Nikhil

--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to