I want to convert spatial data from postgres to some basic formats (shp, geopackage, csv, xlsx, gml... ) using python gdal functionality. I read the answer to this question: Using ogr2ogr to convert GML to shapefile in Python?
I downloaded ogr2ogr.py and tried to convert data from postgres to some formats but I get an error saying:
KML driver failed to create /home/.../out.kml
This is the method I am using:
ogr2ogr.main(["", "-f", "KML", "/home/.../out.kml", "PG:dbname='dbname' host='host' port=5432 user='username' password='password'", "-sql", "SELECT column1, column2 FROM schema.table"])