psycopg2

Creating postgres schemas using psycopg cur.execute

*爱你&永不变心* 提交于 2019-12-12 02:56:19
问题 My python application allows users to create schemas of their naming. I need a way to protect the application from sql injections. The SQL to be executed reads CREATE SCHEMA schema_name AUTHORIZATION user_name; The psycopg documentation (generally) recommends passing parameters to execute like so conn = psycopg2.connect("dbname=test user=postgres") cur = conn.cursor() query = 'CREATE SCHEMA IF NOT EXISTS %s AUTHORIZATION %s;' params = ('schema_name', 'user_name') cur.execute(query, params)

How can I inherit from psycopg2?

余生颓废 提交于 2019-12-12 02:25:55
问题 I'm trying inherit psycopg2 like this: import psycopg2 class myp(psycopg): pass ii = myp ii.connect(database = "myDataBase", user = "myUser", password="myPassword") Then it throws an error: class myp(psycopg2._psycopg): TypeError: Error when calling the metaclass bases module.__init__() takes at most 2 arguments (3 given) Is it possible to inherit from psycopg2 library? EDIT: I want to use different databases, so I just have to change the class MyDatabase. something like a wrapper. example:

How do I properly use psycopg2 with cherrypy?

安稳与你 提交于 2019-12-12 02:18:16
问题 I wrote a CherryPy webapp the other day. Some data is queried from PostgreSQL and I use psycopg2 for that. While everything worked alright in my local testing, it sometimes falls apart in real conditions (much more pageloads). Unfortunately, I do not have the exact traceback messages right now but they were about not being able to connect or a connection being closed already if I recall correctly. I will add them as soon as I can. Psycopg / Postgres : Connections hang out randomly seems to

psycopg2 not all arguments converted during string formatting

与世无争的帅哥 提交于 2019-12-12 01:38:05
问题 I am trying to use psycopg2 to insert a row into a table from a python list, but having trouble with the string formatting. The table has 4 columns of types (1043-varchar, 1114-timestamp, 1043-varchar, 23-int4). I have also made attempts with 1082-date instead of timestamp, and 21-int2 instead of int4. The following statement works fine in pgAdmin or through a psycopg2 cursor execution without string formatting: INSERT INTO ssurgo.distmd VALUES ('5', '2015-01-01', 'Successful', 4891); However

psycopg2 and infinite python script

假如想象 提交于 2019-12-12 00:51:06
问题 I have an infinite script written in Python which connects to Postgresql and inserts there a record when the person appears in front of the camera connected to my computer. I would like to know what is the best way to connect (and store connection) to the database, if it is necessary to connect and close every time when the person appears or if I can somehow store connection. Because when I create a connection before the infinite loop and there is no activity in front of the camera, the

Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID

人走茶凉 提交于 2019-12-11 22:31:16
问题 I recently upgraded to Mac OS X Lion and am trying to get psycopg2 working again with python 2.6. The instructions on previous sites to force Python to run in 32 bit more (seen places like here: http://favosdream.blogspot.com/2009/09/make-psycopg2-and-readline-work-in-snow.html ) aren't giving any luck. Even trying to force python to 32 bit using arch -i386 python is still giving me the error: symbol not found: _PQbackendPID Referenced from: /Library/Python/2.6/site-packages/psycopg2/_psycopg

How can I force Python to use specific libraries ( psycopg2 & osx )?

我的梦境 提交于 2019-12-11 19:29:04
问题 I figured out what the underlying problem is with many of the current osx installations ( such as http://psycopg.lighthouseapp.com/projects/62710/tickets/111-library-not-loaded-libssl100dylib and python pip install psycopg2 install error ) A lot of people use the PostgreSQL installer from EnterpriseDB ; probably because it's the first option in http://www.postgresql.org/download/macosx/ If you install with that, it installs all the needed binaries and libraries into it's private versioned

Using a dictionary to pass parameters to postgresql statement in python

扶醉桌前 提交于 2019-12-11 18:31:27
问题 I have defined a dictionary which contains several parameters and their values which will ultimately be used to build a SQL Query query_params = collections.OrderedDict( {'table_name':'publilc.churn_data', 'date_from':'201712', 'date_to':'201805', 'class_target':'NPA' }) The parameters are to be used in the below query: sql_data_sample = str("""select * from %s # get value of table_name where dt = %s #get value of date_from and target in ('ACTIVE') --------------------------------------------

Error importing psycopg2._psycopg when using uWSGI

大兔子大兔子 提交于 2019-12-11 16:51:53
问题 I'm getting the following import error when I try to run uwsgi --ini <my uwsi ini file> : Traceback (most recent call last): File "/var/www/mysite/venv/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 20, in <module> import psycopg2 as Database File "/var/www/mysite/venv/lib/python3.5/site-packages/psycopg2/__init__.py", line 50, in <module> from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: No module named 'psycopg2._psycopg' However,

Psycopg2 Installing, Not Being Read by Python - OS 10.8.4, Python 2.7, PostgreSQL 9.2

眉间皱痕 提交于 2019-12-11 16:48:55
问题 OS 10.8.4, Python 2.7, PostgreSQL 9.2 I've been spending the past 10+ hours trying to get Psycopg2 installed for Django and am now receiving warnings and a failure that Google can't seem to help me with: After cleaning out all existing Psycopg2 & PostgreSQL files, reinstalling PostgreSQL 9.2 and Python 2.7, I was still getting the _PQbackendPID error when trying to install Psycopg2 with Pip. So I tried changing the ARCHFLAGS setting on install: $ sudo env ARCHFLAGS="-arch i386 -arch x86_64"