如何将Heroku Discord Bot连接到CockroachDB?

7fhtutme  于 2023-06-23  发布在  其他
关注(0)|答案(1)|浏览(157)

我目前有一个不和谐的机器人与Nextcord.py与工作数据库上的CockroachDB。我设法在Heroku上托管和部署了机器人,命令可以工作,但我似乎无法让数据库工作。
Heroku日志中的错误行是2023-06-14T10:29:55.300444+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
当我尝试使用Worker而不是Web时,当我尝试一个命令时,我会得到这个错误。

2023-06-14T10:46:44.323804+00:00 app[worker.1]: psycopg2.OperationalError: connection to server at "enter server here" (IP), port 32481 failed: Connection timed out
2023-06-14T10:46:44.323805+00:00 app[worker.1]:     Is the server running on that host and accepting TCP/IP connections?
2023-06-14T10:46:44.323806+00:00 app[worker.1]: connection to server at "enter server here" (IP), port 32481 failed: Connection timed out
2023-06-14T10:46:44.323806+00:00 app[worker.1]:     Is the server running on that host and accepting TCP/IP connections?
2023-06-14T10:46:44.323806+00:00 app[worker.1]: connection to server at ""enter server here" (IP), port 32481 failed: Connection timed out
2023-06-14T10:46:44.323807+00:00 app[worker.1]:     Is the server running on that host and accepting TCP/IP connections?

我使用Psycopg 2手动连接到CockroachDB,代码如下:

conn = psycopg2.connect(
        host = os.getenv('HOST'),
        port = os.getenv('PORT'),
        database = os.getenv('DATABASE'),
        user = os.getenv('USER'),
        password = os.getenv('PASSWORD'),
        sslmode = os.getenv('SSLMODE')
        )

其中环境变量为:

HOST=calmer-herring-5909.7tc.cockroachlabs.cloud
PORT=*port*
DATABASE=*database*
USER=*user*
PASSWORD=*password*
SSLMODE=verify-full

这是一个Heroku相关的问题吗?我看不出哪里出了问题。谢谢!

ecfdbz9o

ecfdbz9o1#

我终于找到了解决办法。我将Heroku dyno改为Worker而不是Web,并且在连接字符串中,SSLMODE应该等于“require”,因为无法安装CockroachDB连接到数据库所需的CA证书。如果您使用任何其他SSLMODE而不是“required”(无论是verify-full还是disable),它都不会工作。希望能帮上忙

相关问题