从SqlAlchemy通过pg8000连接到postgres工作正常,直到我在postgres上启用了SSL。
db = create_engine('postgresql+pg8000://user:pass@hostname/dbname', echo=True).connect()
现在它似乎失败了,原因是:
File "/Library/Python/2.7/site-packages/pg8000/core.py", line 872, in __init__
raise InterfaceError("communication error&
App engine标准只支持Python2,并且库必须是纯python,所以我使用SQLAlchemy和pg8000连接到Postgres实例(纯python,而不是psycopg2 )。建立连接没有任何问题,但当尝试插入时,我得到以下错误,我不完全理解:
<type 'memoryview'> has type <type 'memoryview'>, but expected one of: str, unicode
导致此行为的代码片段:
event = self.generate_view(body)
self.write_ev
我无法通过远程主机连接postgres数据库,使用psycopg2并获得以下错误
错误:
File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out
这与sqlalchemy和pg8000相关。
我到处都读到应该关闭ResultProxy对象,以便连接可以返回到池中。
本地测试数据库最多允许100连接:
$ psql -h 127.0.0.1 -U postgres
Password for user postgres:
psql (9.5.5, server 9.6.0)
WARNING: psql major version 9.5, server major version 9.6.
Some psql features might not work.
Type "help" for help.
我正在尝试使用heroku pg:psql postgresql-rigid-33416 --app murmuring-ocean-62645连接到heroku的postgres数据库,但是我收到了这条消息
--> Connecting to postgresql-rigid-33416
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "ec2-50-17-225-140.compute-1.amazo
在我的database.yml文件中,我指定要查找一个特定的数据库模式( database ),但是当我运行rake db:schema:dump时,会得到一个错误:
ActiveRecord::StatmentInvalid: PG::SyntaxError: ERROR: syntax error at or near "-"
LINE 1: SET Search_path TO data-mart
^
很明显它不喜欢连字符,所以我该怎么修复呢?我不能更改架构名称。我也试过用引号来包围它。
我试图在SLES12机器上使用Perl5.26.1连接到PostgreSQL12.1 DB实例,但是遇到了错误。我的测试脚本很简单。
#!/usr/pkgs/perl/5.26.1/bin/perl
use DBI;
my $dbname = "XXX";
my $host = "XXX";
my $port = XXX;
my $username = "XXX";
my $password = "XXX";
my $dbh = DBI -> connect("dbi:Pg:dbname=$dbn
我在Linux机器上设置了postgres 10.4,有时pg_hba.conf顶部会随机设置规则,只允许用户"pgdbadm“进行MD5连接。我不确定数据库是否被黑客入侵,但在更改密码并检查pgdbadm是否不存在之后,我仍然不时地看到新的规则。数据库可能被破坏了吗?
如果我没记错的话,这三条规则如下:
local all all 0.0.0.0/0 reject
host all postgres 0.0.0.0/0 reject
host all pgdbadm 0.0.0.0/0 md5
如能对正在发生的事情作出任何解释,以及可能的解决办法,我们将不胜感激。
编辑:我发现在设置
我正在用postgresql DB运行python 2.7.3和django 1.5.1。在设置了一个简单的django应用程序后,我得到了一个OperationalError at FATAL: password authentication failed for user "postgres"。当我检查本地变量时,我发现psycopg2连接接受了错误的密码。我已经在django settings.py文件中指定了正确的密码。此外,manage.py syncdb运行良好,这个问题出现了2/3次。
pg_hba.conf中的所有身份验证方法都设置为md5 and setti
我试图模仿我所写的红宝石刮板,但它只适用于python环境。我决定使用lxml和请求来完成这个任务。我的问题是分页:
base_url = "http://example.com/something/?page=%s"
for url in [base_url % i for i in xrange(10)]:
r = requests.get(url)
我对python和这个库并不熟悉,所以我不确定执行等效的ruby代码的最佳方法:
last_pg = (page.xpath("//div[contains(@class, 'b-tabs-ut
我已经创建了一个使用Postgresql的python应用程序。我在进行开发时使用了psycopg2库(v2.8.4),但在尝试将其安装在豆茎上时,它给出了以下错误:
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:
python
我正在尝试设置一个正确的连接字符串,以便从php 5.4连接到PG 9.2。小菜一碟,除非用户名包含一个space...Maybe,否则有人可以帮我得到正确的报价。
我的尝试:
$dbconn = pg_connect('host=localhost dbname='.$database.' user="demo demo" password='.$password)
or die('connect failed');
is rejected by the server:pg_connect(): Unable to conne
我在Python中与库psycopg2一起使用postgres。连接到数据库后,我将尝试检查具有给定名称的表是否存在。在postgres,我是这样做的:
\connect myDB
select exists(select * from pg_tables where schemaname='public' AND tablename='mytable';)
如果该表存在,但如果不存在,则可以这样做。在python中,我使用以下行进行操作:
import psycopg2 as pg
from psycopg2.extensions import ISOLATI