Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/bd.py Secret

Created June 18, 2019 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/bddca5dad97b431d0061d8d9abcbd0a8 to your computer and use it in GitHub Desktop.
Save parzibyte/bddca5dad97b431d0061d8d9abcbd0a8 to your computer and use it in GitHub Desktop.
"""
Conexión a PostgreSQL con Python
Ejemplo de CRUD evitando inyecciones SQL
@author parzibyte
Más tutoriales en:
parzibyte.me/blog
"""
import psycopg2
# Recomendado: https://parzibyte.me/blog/2018/12/20/args-kwargs-python/
try:
credenciales = {
"dbname": "mascotas",
"user": "parzibyte",
"password": "hunter2",
"host": "localhost",
"port": 5432
}
conexion = psycopg2.connect(**credenciales)
except psycopg2.Error as e:
print("Ocurrió un error al conectar a PostgreSQL: ", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment