psycopg2

connecting to amazon rds with psycopg2 via lambda

一世执手 提交于 2020-01-05 09:26:10
问题 my code on aws lambda: import sys, boto3, logging, rds_config, psycopg2 rds_host = "hostname" name = rds_config.db_username password = rds_config.db_password db_name = rds_config.db_name s3 = boto3.resource('s3') rds_client = boto3.client('rds',aws_access_key_id=Access_Key,aws_secret_access_key=Secret_Access_Key) instances = rds_client.describe_db_instances() print (instances) try: conn = psycopg2.connect(host=rds_host, database=db_name, user=name, password=password) cur = conn.cursor()

Avoiding duplicated data in PostgreSQL database in Python

北慕城南 提交于 2020-01-04 07:28:16
问题 I am working on PostgreSQL and psycopg2. Trying to get feed data which is updated every after 10 mins and keep this feeds contents in PostgreSQL database.My target is to retrieve and print those data from that table. But facing problem as duplicate data is also stored in the database every time I run that script due to insertion operation on table. To get out off this problem ,I made primary key constraint of column location_title in table Locations-musiq1 where I intend to store my feed data

Avoiding duplicated data in PostgreSQL database in Python

不羁岁月 提交于 2020-01-04 07:28:09
问题 I am working on PostgreSQL and psycopg2. Trying to get feed data which is updated every after 10 mins and keep this feeds contents in PostgreSQL database.My target is to retrieve and print those data from that table. But facing problem as duplicate data is also stored in the database every time I run that script due to insertion operation on table. To get out off this problem ,I made primary key constraint of column location_title in table Locations-musiq1 where I intend to store my feed data

Cannot install psycopg2 Ubuntu

落花浮王杯 提交于 2020-01-04 04:29:07
问题 Trying to get a server ready for a django project and I'm running into some issues with setup for postgres. I'm following this guide: https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html And I'm at step 5: Now, we need to configure postgreSQL so that it can communicate with our Django application. For this, install psycopg2 database adapter. But this adapter have some package dependencies, so first install them. run: (django_env) $ sudo apt-get install libpq-dev python3-dev then

InternalError: current transaction is aborted, commands ignored until end of transaction block

被刻印的时光 ゝ 提交于 2020-01-04 02:35:14
问题 I'm getting this error when doing database calls in a sub process using multiprocessing library. Visit : Pastie InternalError: current transaction is aborted, commands ignored until end of transaction block this is to a Postgre Database, using psycopg2 driver in web.py . However if I use threading.Thread instead of multiprocessing.Process I don't get this error. Any idea how to fix this? 回答1: multiprocessing works (on UNIX systems) by forking the current process. If you have an existing

Is SQLAlchemy/psycopg2 connection to PostgreSQL database encrypted

為{幸葍}努か 提交于 2020-01-04 01:57:08
问题 When I use SQLAlchemy with an external postgreSQL server, is the connection secured/encrypted? from sqlalchemy.engine import create_engine engine = create_engine('postgresql://scott:tiger@ip:5432/mydatabase') What about psycopg2? 回答1: Your connection string does not indicate secure connection. However, sometimes connection might be secure nevertheless, but it is unlikely. To have a secure connection to PostgreSQL database you can use sslmode parameter. engine = create_engine('postgresql:/

Python psycopg2 copy_from() to load data throws error for null integer values: DataError: invalid input syntax for integer: “”

怎甘沉沦 提交于 2020-01-03 17:29:39
问题 I am trying to load data from a StringIO object of python into a Postgres database table using psycopg2's copy_from() method. My copy_from fails on the first record itself specifically for a particular (nullable) integer column which has null value ('' without quotes). I have also tried using Python's None keyword instead of '' for NULL values. It throws me the following error: DataError: invalid input syntax for integer: "" CONTEXT: COPY , line 1, column : "" The code looks something like

Effective query merging more than 2 subqueries

最后都变了- 提交于 2020-01-03 16:13:33
问题 I have a database with books (primary key: bookID) characterNames (foreign key: books.bookID) locations (foreign key: books.bookID) The in-text-position of character names and locations are saved in the corresponding tables. I'm writing a Pythonscript using psycopg2, finding all occurences of given character names and locations in books. I only want the occurences in books, where both the character name AND the location are found. Here I already got a solution for searching one location and

Django: using same test database in a separate thread

做~自己de王妃 提交于 2020-01-03 09:02:14
问题 I am running pytests using a test database with the following DB settings. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'something', 'PASSWORD': 'password', }, } Using the @pytest.mark.django_db, my test functions access a database called 'test_postgres' created for the tests. @pytest.mark.django_db def test_example(): from django.db import connection cur_ = connection.cursor() print cur_.db.settings_dict outputs: {'ENGINE':

Python psycopg2 error vars function

不羁的心 提交于 2020-01-02 21:56:52
问题 I have a piece of code that work fine on a server and don't work on other server ( Linux servers) import psycopg2,psycopg2.extras conn = psycopg2.connect("host=xx.x.x.x dbname=dev user=user password=pass" ) parentId='272' dbCur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) dbCur.execute('select * from "treeItem" where "parentId" = %s order by "order"',(parentId,)) for row in dbCur: print type(row) print row.__dict__ vars(row) dbCur.close() conn.close() The output on the