如何解决无法连接到 Pokertracker postgreSQL 数据库
我正在关注 this tutorial 以连接到存储在我计算机上的 PostgreSQL 数据库。 我使用的是 Windows 10 并且我已经安装了 PostgreSQL 9.3
我运行以下代码:
import psycopg2
class PostgreSQL():
def __init__(self):
self.conecta()
def conecta(self):
#establishing the connection
conn = psycopg2.connect(
database="PokerTracker 4 Database",user='postgres',password='dbpass',host='localhost',port= '5432')
#Creating a cursor object using the cursor() method
cursor = conn.cursor()
#Executing an MYSQL function using the execute() method
cursor.execute("select version()")
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print("Connection established to: ",data)
conn.close()
if __name__=='__main__':
PostgreSQL()
我在运行脚本时从 cmd 收到以下错误:
C:\Users\USUARIO\Desktop\OMAHA>python postgresql.py
Traceback (most recent call last):
File "C:\Users\USUARIO\Desktop\OMAHA\postgresql.py",line 18,in <module>
PostgreSQL()
File "C:\Users\USUARIO\Desktop\OMAHA\postgresql.py",line 4,in __init__
self.conecta()
File "C:\Users\USUARIO\Desktop\OMAHA\postgresql.py",line 7,in conecta
conn = psycopg2.connect(
File "C:\Users\USUARIO\AppData\Local\Programs\Python\Python39\lib\site-packages\psycopg2\__init__.py",line 127,in connect
conn = _connect(dsn,connection_factory=connection_factory,**kwasync)
psycopg2.OperationalError
我做错了什么?我从教程中复制了代码。
解决方法
如果有人试图连接到 Pokertracker 数据库,错误是数据库名称不正确。继续 pokertracker 到文件->打开用户数据文件夹。打开 config 文件夹,打开 pokertracker.cfg 就可以看到所有信息。
就我而言,这是参数:
import psycopg2
class PostgreSQL():
def __init__(self):
self.conecta()
def conecta(self):
hostname = 'localhost'
username = 'postgres'
password = 'dbpass'
database = 'PT4DB'
myConnection = psycopg2.connect( host=hostname,user=username,password=password,dbname=database )
cursor = myConnection.cursor()
cursor.execute("""SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public'""")
for table in cursor.fetchall():
print(table)
myConnection.close()
if __name__=='__main__':
PostgreSQL()
你有笔记表。您不能编辑笔记,它们受到 Pokertracker 系统的保护。干杯
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。