Connecting to PostgreSQL using pyodbc

女生的网名这么多〃 提交于 2019-12-01 20:57:07

问题


I have a PostgreSQL running on localhost. I have psqlODBC Driver installed. Now when I try to connect to the server using pyodbc as:

import pyodbc
connection = pyodbc.connect("DRIVER={psqlOBDC};SERVER=localhost;DATABASE=weather;UID=postgres;PWD=password")

but I get this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('08001', '[08001] Already connected. (202) (SQLDriverConnect)')

Whats the problem?

Thanks.


回答1:


Of course you must install ODBC driver. I don't know Mac, but in Windows there is ODBC Manager where you configure Data Sources. For PostgreSQL driver there is also "Test" button to check if connection can be established.

As fog noticed you can also use other technology to connect to PostgreSQL. If you can use Jython then you can use JDBC driver. There are also native drivers like psycopg, PyGreSQL and pg8000 (pure Python). Can you give them try?



来源:https://stackoverflow.com/questions/10827471/connecting-to-postgresql-using-pyodbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!