[求助] python+flask+postgresql 环境下 SQLalchmy 发生错误?_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
2
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2215 | 回复: 1   主题: [求助] python+flask+postgresql 环境下 SQLalchmy 发生错误?        下一篇 
qq_gaga
注册用户
等级:新兵
经验:27
发帖:1
精华:0
注册:2015-12-14
状态:离线
发送短消息息给qq_gaga 加好友    发送短消息息给qq_gaga 发消息
发表于: IP:您无权察看 2015-12-14 17:32:24 | [全部帖] [楼主帖] 楼主

在下目前刚开始接触

用官方范例 

但是却无法写入 

qqq.py 
import sys
sys.path.append("/var/www/html/ft/ft2")
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import dbtest
app = Flask(__name__) 
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://frank:1qaz2wsx#EDC@localhost/mydb'
db = SQLAlchemy(app)
if __name__ == '__main__':
    db.create_all()


 

 

而错误信息如下:

 

Traceback (most recent call last):
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 936, in _do_get
 
    return self._pool.get(wait, self._timeout)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/util/queue.py", line 145, in get
 
    raise Empty
 
sqlalchemy.util.queue.Empty
 
 
 
During handling of the above exception, another exception occurred:
 
 
 
Traceback (most recent call last):
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 89, in connect
 
    return dialect.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/default.py", line 376, in connect
 
    return self.dbapi.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/psycopg2/__init__.py", line 164, in connect
 
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
 
psycopg2.OperationalError: FATAL:  Ident authentication failed for user "frank"
 
 
 
 
 
The above exception was the direct cause of the following exception:
 
 
 
Traceback (most recent call last):
 
  File "qqq.py", line 11, in <module>
 
    db.create_all()
 
  File "/usr/local/lib/python3.3/site-packages/flask_sqlalchemy/__init__.py", line 856, in create_all
 
    self._execute_for_all_tables(app, bind, 'create_all')
 
  File "/usr/local/lib/python3.3/site-packages/flask_sqlalchemy/__init__.py", line 848, in _execute_for_all_tables
 
    op(bind=self.get_engine(app, bind), tables=tables)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/sql/schema.py", line 3317, in create_all
 
    tables=tables)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1554, in _run_visitor
 
    with self._optional_conn_ctx_manager(connection) as conn:
 
  File "/usr/local/lib/python3.3/contextlib.py", line 48, in __enter__
 
    return next(self.gen)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1547, in _optional_conn_ctx_manager
 
    with self.contextual_connect() as conn:
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1737, in contextual_connect
 
    self.pool.connect(),
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 332, in connect
 
    return _ConnectionFairy._checkout(self)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 630, in _checkout
 
    fairy = _ConnectionRecord.checkout(pool)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 433, in checkout
 
    rec = pool._do_get()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 949, in _do_get
 
    return self._create_connection()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 278, in _create_connection
 
    return _ConnectionRecord(self)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 404, in __init__
 
    self.connection = self.__connect()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 530, in __connect
 
    connection = self.__pool._creator()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 95, in connect
 
    connection_invalidated=invalidated
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/util/compat.py", line 178, in raise_from_cause
 
    reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/util/compat.py", line 171, in reraise
 
    raise value.with_traceback(tb)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 89, in connect
 
    return dialect.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/default.py", line 376, in connect
 
    return self.dbapi.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/psycopg2/__init__.py", line 164, in connect
 
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
 
sqlalchemy.exc.OperationalError: (OperationalError) FATAL:  Ident authentication failed for user "frank"
 
 None None
 
[root@sinyi-tech ft2]# vi qqq.py
 
[root@sinyi-tech ft2]# vi qqq.py
 
[root@sinyi-tech ft2]# python qqq.py
 
Traceback (most recent call last):
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 936, in _do_get
 
    return self._pool.get(wait, self._timeout)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/util/queue.py", line 145, in get
 
    raise Empty
 
sqlalchemy.util.queue.Empty
 
 
 
During handling of the above exception, another exception occurred:
 
 
 
Traceback (most recent call last):
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 89, in connect
 
    return dialect.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/default.py", line 376, in connect
 
    return self.dbapi.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/psycopg2/__init__.py", line 164, in connect
 
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
 
psycopg2.OperationalError: FATAL:  Ident authentication failed for user "frank"
 
 
 
 
 
The above exception was the direct cause of the following exception:
 
 
 
Traceback (most recent call last):
 
  File "qqq.py", line 11, in <module>
 
    db.create_all()
 
  File "/usr/local/lib/python3.3/site-packages/flask_sqlalchemy/__init__.py", line 856, in create_all
 
    self._execute_for_all_tables(app, bind, 'create_all')
 
  File "/usr/local/lib/python3.3/site-packages/flask_sqlalchemy/__init__.py", line 848, in _execute_for_all_tables
 
    op(bind=self.get_engine(app, bind), tables=tables)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/sql/schema.py", line 3317, in create_all
 
    tables=tables)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1554, in _run_visitor
 
    with self._optional_conn_ctx_manager(connection) as conn:
 
  File "/usr/local/lib/python3.3/contextlib.py", line 48, in __enter__
 
    return next(self.gen)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1547, in _optional_conn_ctx_manager
 
    with self.contextual_connect() as conn:
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1737, in contextual_connect
 
    self.pool.connect(),
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 332, in connect
 
    return _ConnectionFairy._checkout(self)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 630, in _checkout
 
    fairy = _ConnectionRecord.checkout(pool)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 433, in checkout
 
    rec = pool._do_get()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 949, in _do_get
 
    return self._create_connection()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 278, in _create_connection
 
    return _ConnectionRecord(self)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 404, in __init__
 
    self.connection = self.__connect()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/pool.py", line 530, in __connect
 
    connection = self.__pool._creator()
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 95, in connect
 
    connection_invalidated=invalidated
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/util/compat.py", line 178, in raise_from_cause
 
    reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/util/compat.py", line 171, in reraise
 
    raise value.with_traceback(tb)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 89, in connect
 
    return dialect.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/SQLAlchemy-0.9.6-py3.3-linux-x86_64.egg/sqlalchemy/engine/default.py", line 376, in connect
 
    return self.dbapi.connect(*cargs, **cparams)
 
  File "/usr/local/lib/python3.3/site-packages/psycopg2/__init__.py", line 164, in connect
 
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
 
sqlalchemy.exc.OperationalError: (OperationalError) FATAL:  Ident authentication failed for user "frank"
 
 None None





赞(0)    操作        顶端 
一个路过的
版主
等级:中校
经验:1970
发帖:34
精华:2
注册:2015-9-2
状态:离线
发送短消息息给一个路过的 加好友    发送短消息息给一个路过的 发消息
发表于: IP:您无权察看 2015-12-14 17:42:37 | [全部帖] [楼主帖] 2  楼

看来主因是这段:  

 conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL:  Ident authentication failed for user "frank"

确定帐密与数据库 mydb 有正确在 localhost 上的 PostgreSQL 设定了吗?


该贴被一个路过的编辑于2015-12-14 17:43:01


赞(0)    操作        顶端 
总帖数
2
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论