<div dir="ltr">Hi,<br><br>I am writing a short python script to create a PostGIS table, loop through a csv file, run a series of grass commands, then save the final vector polygons to the PostGIS table.  All of the PostGIS commands were being issued by the db.execute.  <br><br>In the code below I got the message:<br>ERROR: Unable to open database <host=localhost,dbname=ss_basin_test><br><br>As seen in the 30th line I tried to send user & password along with the database info but that gave an error as well. When I tried to run db.login it said I had to use the "overwrite" flag.  If I overwrite the login info this script I will have to reset it when I am done and I am not sure how to do that.  <br><br>How do I connect to the db with db.execute and send the user/password information?<br>The first half of my code is below.<br><br>thanks,<br><br>Phil<br> <br><br><br># IMPORT CSV & LOOP THROUGH COORDINATES FOR r.water.outlet<br>import os<br>import sys<br><br>#set up GRASS environment variables<br>sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))<br>import grass.script as g<br>import grass.script.setup as gsetup<br>gisbase = os.environ['GISBASE']<br><br>gisdb = 'E:\DEM_12_5\grassdata'<br>location = 'dem_12_5'<br>mapset = 'PERMANENT'<br><br>#     first join the new snap table's cat column to the original attribute table<br># v.out.ascii input=th_ss_aem_snap_r5@PERMANENT type=point output=C:\data\th_ss_aem_snap_r5.csv columns=COD_MUESTR format=point separator=comma precision=20<br>txtfile = 'c:/data/th_ss_aem_snap_r5.csv'<br>txtfileWKT = 'c:/data/th_ss_aem_snap_r5_WKT.txt'<br>pgsrid = '32618'<br><br>pg_user = 'postgres'<br>pg_user_pwd = 'xxxx'<br>pg_schema = 'basin'<br>pg_tbl_name = 'samp_basin'<br>pg_host = 'localhost'<br>pg_dbname = 'ss_basin_test'<br><br>txt_pg_tbl_create = 'CREATE TABLE ' + pg_tbl_name + ' (x double precision, y double precision, samp_id character varying(254) PRIMARY KEY, geom geometry(POLYGON, ' + pgsrid + ') )'<br><br>#txt_pg_db = 'host=' + pg_host + ',dbname=' + pg_dbname + ',user=' + pg_user + ',password=' + pg_user_pwd<br>txt_pg_db = 'host=' + pg_host + ',dbname=' + pg_dbname<br><br>gsetup.init(gisbase, gisdb, location, mapset)<br><br># Create PostGIS Polygon Table<br># g.run_command('db.login', driver='pg', user=pg_user, password=pg_user_pwd )<br>g.run_command('db.execute', sql=txt_pg_tbl_create , driver='pg', database=txt_pg_db, schema=pg_schema)<br><br></div>