Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用sqlalchemy的溢出错误_Python_Postgresql_Sqlalchemy - Fatal编程技术网

Python 使用sqlalchemy的溢出错误

Python 使用sqlalchemy的溢出错误,python,postgresql,sqlalchemy,Python,Postgresql,Sqlalchemy,使用SQLAlchemy连接到数据库时出现问题。我使用这个软件包很长一段时间来连接我们所有的数据库。最近尝试连接到新数据库时,出现以下错误: from sqlalchemy import create_engine engine = create_engine('postgresql://username:password@host/db') engine.connect() Traceback (most recent call last): File "<stdin>",

使用SQLAlchemy连接到数据库时出现问题。我使用这个软件包很长一段时间来连接我们所有的数据库。最近尝试连接到新数据库时,出现以下错误:

from sqlalchemy import create_engine
engine = create_engine('postgresql://username:password@host/db')
engine.connect()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1778, in connect
    return self._connection_cls(self, **kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 60, in __init__
    self.__connection = connection or engine.raw_connection()
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1847, in raw_connection
    return self.pool.unique_connection()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 280, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 644, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 440, in checkout
    rec = pool._do_get()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 963, in _do_get
    return self._create_connection()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 285, in _create_connection
    return _ConnectionRecord(self)
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 416, in __init__
    exec_once(self.connection, self)
  File "C:\Python27\lib\site-packages\sqlalchemy\event\attr.py", line 250, in exec_once
    self(*args, **kw)
  File "C:\Python27\lib\site-packages\sqlalchemy\event\attr.py", line 260, in __call__
    fn(*args, **kw)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\strategies.py", line 157, in on_connect
    do_on_connect(conn)
  File "C:\Python27\lib\site-packages\sqlalchemy\dialects\postgresql\psycopg2.py", line 530, in on_connect
    for fn in fns:
OverflowError: Python int too large to convert to C long
从sqlalchemy导入创建引擎
引擎=创建引擎('postgresql://username:password@主机/数据库')
引擎连接()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Python27\lib\site packages\sqlalchemy\engine\base.py”,第1778行,在connect中
返回self.\u连接\u cls(self,**kwargs)
文件“C:\Python27\lib\site packages\sqlalchemy\engine\base.py”,第60行,在\uuu init中__
self.\uuu connection=连接或引擎.raw\u连接()
原始连接中的文件“C:\Python27\lib\site packages\sqlalchemy\engine\base.py”,第1847行
返回self.pool.unique_connection()
文件“C:\Python27\lib\site packages\sqlalchemy\pool.py”,第280行,处于唯一\u连接中
返回\u连接\u签出(自我)
文件“C:\Python27\lib\site packages\sqlalchemy\pool.py”,第644行,在\u签出中
fairy=\u ConnectionRecord.checkout(池)
文件“C:\Python27\lib\site packages\sqlalchemy\pool.py”,第440行,在签出中
rec=pool.\u do\u get()
文件“C:\Python27\lib\site packages\sqlalchemy\pool.py”,第963行,在\u do\u get中
返回self.\u创建\u连接()
文件“C:\Python27\lib\site packages\sqlalchemy\pool.py”,第285行,位于\u create\u connection中
返回连接记录(自身)
文件“C:\Python27\lib\site packages\sqlalchemy\pool.py”,第416行,在\uuu init中__
执行一次(self.connection,self)
文件“C:\Python27\lib\site packages\sqlalchemy\event\attr.py”,第250行,在exec\u中
自(*args,**kw)
文件“C:\Python27\lib\site packages\sqlalchemy\event\attr.py”,第260行,在调用中__
fn(*参数,**千瓦)
文件“C:\Python27\lib\site packages\sqlalchemy\engine\strategies.py”,第157行,on\u connect
do_on_connect(连接)
文件“C:\Python27\lib\site packages\sqlalchemy\dialogs\postgresql\psycopg2.py”,第530行,在on\u connect中
对于fn中的fn:
溢出错误:Python int太大,无法转换为C long

奇怪的是,对于某些数据库,我的连接工作得非常好,但是对于这个特定的数据库,我得到了OverflowError。你知道为什么会这样吗?我们正在使用postgresql

问题是由psycopg2中的hstore实现引起的。在connect上,psycopg2尝试使用获取hstore OID的本机hstore实现。这些OID超出C长范围值,因此会抛出错误

您可以通过在create\u引擎中传递use\u native\u hstore=False来修复此问题

engine = create_engine('postgresql://username:password@host/db', use_native_hstore=False)