psycopg2

psycopg2.OperationalError: FATAL: unsupported frontend protocol 1234.5679: server supports 2.0 to 3.0

你说的曾经没有我的故事 提交于 2020-03-15 07:59:10
问题 I'm using Macbook Psycopg2 works well when connecting the localhost db (PostgreSQL on Mac). The error was raised when I tried to connect PostgreSQL db on a Windows10. the following code is what I have for connection, the host is just the IP of the windows10 db= psycopg2.connect(database='dbname',user='username',password="secret",host="192.168.3.9",port="5432") Errors: File "path/to/psycopg2/__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, *

Error code when installing psycopg2 in requirements.txt in django

纵饮孤独 提交于 2020-03-15 06:41:29
问题 I've tried to manually install only the psycopg2 module. As well as with a pip3 install -r requirements.txt. If anybody has encountered this error before, please provide appreciated guidance! ERROR: Failed building wheel for psycopg2 Running setup.py clean for psycopg2 Failed to build psycopg2 Installing collected packages: psycopg2 Running setup.py install for psycopg2 ... error ERROR: Command errored out with exit status 1: command: /Users/DavidKronish/dev/citram/MyCampus-Backend/citramenv

How to mock psycopg2 cursor object?

独自空忆成欢 提交于 2020-03-12 07:31:07
问题 I have this code segment in Python2: def super_cool_method(): con = psycopg2.connect(**connection_stuff) cur = con.cursor(cursor_factory=DictCursor) cur.execute("Super duper SQL query") rows = cur.fetchall() for row in rows: # do some data manipulation on row return rows that I'd like to write some unittests for. I'm wondering how to use mock.patch in order to patch out the cursor and connection variables so that they return a fake set of data? I've tried the following segment of code for my

Trying to create a Redshift table using Python and psycopg2 but the table does not get created with no errors reported

江枫思渺然 提交于 2020-03-05 04:14:06
问题 My codes return no error but I don't see a table in Redshift...if I put "if table exist" and try to create a table I know exists it does nothing and returns no error. Take that out and it will return duplicatetable error which is odd. import boto3 import psycopg2 import sys #Assign global variables data needed to make connection to Redshift DB_NAME = '<database>' CLUSTER_IDENTIFIER = '<clusterName>' DB_USER = '<user>' ENDPOINT = '<clustername>.<randomkey>.us-east-1.redshift.amazonaws.com'

Trying to create a Redshift table using Python and psycopg2 but the table does not get created with no errors reported

不羁的心 提交于 2020-03-05 04:13:07
问题 My codes return no error but I don't see a table in Redshift...if I put "if table exist" and try to create a table I know exists it does nothing and returns no error. Take that out and it will return duplicatetable error which is odd. import boto3 import psycopg2 import sys #Assign global variables data needed to make connection to Redshift DB_NAME = '<database>' CLUSTER_IDENTIFIER = '<clusterName>' DB_USER = '<user>' ENDPOINT = '<clustername>.<randomkey>.us-east-1.redshift.amazonaws.com'

How can I find null values with SELECT query in psycopg?

牧云@^-^@ 提交于 2020-03-03 07:17:23
问题 I am using psycopg2 library in python and the INSERT query works good when I insert null Value with None, but when I want to do SELECT null values, with None doesn't return any. cur.execute("SELECT id FROM registro WHERE id_movil = (%s);", (None,)) This query doesnt return any rows, i dont know where is the error. Anyone know how to make SELECT query's to find null values in a DB? 回答1: First thing to do is find out what query it's turning your command into: print(cur.mogrify("SELECT id FROM

How can I find null values with SELECT query in psycopg?

こ雲淡風輕ζ 提交于 2020-03-03 07:14:06
问题 I am using psycopg2 library in python and the INSERT query works good when I insert null Value with None, but when I want to do SELECT null values, with None doesn't return any. cur.execute("SELECT id FROM registro WHERE id_movil = (%s);", (None,)) This query doesnt return any rows, i dont know where is the error. Anyone know how to make SELECT query's to find null values in a DB? 回答1: First thing to do is find out what query it's turning your command into: print(cur.mogrify("SELECT id FROM

Insert Python NumPy array into PostgreSQL database

限于喜欢 提交于 2020-02-28 07:19:38
问题 How do I insert a large array of coordinates (x,y) into a postgresSQL table? I don't want to use a for loop. It is a raster with 3601x3601 pixels. import numpy as np import psycopg2 # Data example: east = np.linspace(-180.0,180.0,num=10) north = np.linspace(-90.0,90.0,num=10) coor = np.vstack([east, north]) conn = psycopg2.connect("dbname='postgres' user='dbuser' host='localhost' password='dbpass'") cur = conn.cursor() cur.execute("DROP TABLE IF EXISTS foobar;") cur.execute("CREATE TABLE

multiprocessing module and distinct psycopg2 connections

旧时模样 提交于 2020-02-24 09:14:50
问题 I am very puzzled as to the behavior of some multiprocessing code that is using psycopg2 to make queries in parallel to a postgres db. Essentially, I am making the same query (with different params) to various partitions of a larger table. I am using multiprocessing.Pool to fork off a separate query. My multiprocessing call looks like this: pool = Pool(processes=num_procs) results=pool.map(run_sql, params_list) My run_sql code looks like this: def run_sql(zip2): conn = get_connection() curs =

multiprocessing module and distinct psycopg2 connections

一笑奈何 提交于 2020-02-24 09:14:20
问题 I am very puzzled as to the behavior of some multiprocessing code that is using psycopg2 to make queries in parallel to a postgres db. Essentially, I am making the same query (with different params) to various partitions of a larger table. I am using multiprocessing.Pool to fork off a separate query. My multiprocessing call looks like this: pool = Pool(processes=num_procs) results=pool.map(run_sql, params_list) My run_sql code looks like this: def run_sql(zip2): conn = get_connection() curs =