简体   繁体   English

MongoDB Atlas 连接在 Heroku 上不起作用

[英]MongoDB Atlas connection doesn't work on Heroku

I'm creating a discord.py bot for servers.I was looking for free VPS and I have found a Heroku.我正在为服务器创建一个 discord.py bot。我正在寻找免费的 VPS,我找到了一个 Heroku。 I learned how to use it and I hosted my other bot for few hours.我学会了如何使用它,并托管了我的另一个机器人几个小时。 Then I'v created another bot using MongoDB Atlas database.然后我使用 MongoDB Atlas 数据库创建了另一个机器人。 The problem is that when I want to use commands which have to use database it doesn't work and it sends an error.问题是,当我想使用必须使用数据库的命令时,它不起作用并且会发送错误。 Other commands work其他命令有效

I'v made some research, but on some forums they say that It's not possible without giving details of your credit card and some say that it's possible, but doesn't say how.我做了一些研究,但在一些论坛上,他们说不提供信用卡的详细信息是不可能的,有些人说这是可能的,但没有说明如何。

This is the error which I got from heroku logs:这是我从 heroku 日志中得到的错误:

Traceback (most recent call last):
2019-07-25T19:08:37.808124+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
2019-07-25T19:08:37.808126+00:00 app[worker.1]:     await ctx.command.invoke(ctx)
2019-07-25T19:08:37.808132+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/core.py", line 728, in invoke
2019-07-25T19:08:37.808133+00:00 app[worker.1]:     await injected(*ctx.args, **ctx.kwargs)
2019-07-25T19:08:37.808134+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/core.py", line 88, in wrapped
2019-07-25T19:08:37.808136+00:00 app[worker.1]:     raise CommandInvokeError(exc) from exc
2019-07-25T19:08:37.808165+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ServerSelectionTimeoutError: connection closed,connection closed,connection closed

This problem might arise if you have only whitelisted your local IP.如果您仅将本地 IP 列入白名单,则可能会出现此问题。 An easy workaround at the sacrifice of security is to whitelist any IP (0.0.0.0/0) in your MongoDB Atlas cluster.牺牲安全性的一个简单解决方法是将 MongoDB Atlas 集群中的任何 IP (0.0.0.0/0) 列入白名单。 Or you could use VPC peering.或者您可以使用 VPC 对等互连。

I know you have found Heroku, personally I would use repl.it as it doesn't require any money, with great up time, excellent support.我知道您已经找到了 Heroku,我个人会使用 repl.it,因为它不需要任何资金,而且运行时间长,支持出色。 You can run the bot for a long time unlike Heroku.与 Heroku 不同,您可以长时间运行机器人。

If you don't like switching have you used pymongo in the requirements.txt?如果您不喜欢切换,您pymongo在 requirements.txt 中使用过pymongo

This is most likely a SSL certificate error.这很可能是 SSL 证书错误。 You can set your own ssl_certfile option while hosting the databse - you can find the documentation related to that here .您可以在托管数据库时设置自己的ssl_certfile选项 - 您可以在此处找到与相关的文档。

If that is not the case, I'd suggest looking at your server log files and checking out what the error is there.如果情况并非如此,我建议您查看您的服务器日志文件并检查那里的错误。

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM