R
Railway14mo ago
x4zx

MongoDB connection error

When trying to connect to the database, it gives this error:
Authentication failed.", full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
Authentication failed.", full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
45 Replies
Percy
Percy14mo ago
Project ID: f8cc6b6a-813b-4d34-b2f8-20c87fba3048
x4zx
x4zxOP14mo ago
f8cc6b6a-813b-4d34-b2f8-20c87fba3048
x4zx
x4zxOP14mo ago
I was able to connect to the database via mongoDb Compass, but when trying to connect via pymongo - error
No description
Brody
Brody14mo ago
you are using a url and specifying a port, please only use the url as the url would contain the port
x4zx
x4zxOP14mo ago
I originally did it this way, just added a port later to check - maybe that will help
Brody
Brody14mo ago
remove the port
x4zx
x4zxOP14mo ago
alredy
Brody
Brody14mo ago
okay let me know if you still get the same problem
x4zx
x4zxOP14mo ago
The error remains
Brody
Brody14mo ago
same? are you using a railway database?
x4zx
x4zxOP14mo ago
yep
No description
x4zx
x4zxOP14mo ago
yep
Brody
Brody14mo ago
how are you setting the MONGO_URL locally?
x4zx
x4zxOP14mo ago
No description
x4zx
x4zxOP14mo ago
.env file
Brody
Brody14mo ago
have you loaded that .env file? and if so, can you do a sanity check and print the MONGO_URL?
x4zx
x4zxOP14mo ago
one min
Brody
Brody14mo ago
please stop ping replying me
x4zx
x4zxOP14mo ago
okay, sorry
x4zx
x4zxOP14mo ago
No description
Brody
Brody14mo ago
print it right before the mongo client is what i meant
x4zx
x4zxOP14mo ago
Btw, if you don't comment it out, you get this error
No description
Brody
Brody14mo ago
did it print though?
x4zx
x4zxOP14mo ago
No description
Brody
Brody14mo ago
well now theres no errors?
x4zx
x4zxOP14mo ago
the error is still present
Brody
Brody14mo ago
can you connect to mongo from something like dbgate?
x4zx
x4zxOP14mo ago
I don't use one of these, but I was able to connect via mongodb compass
No description
Brody
Brody14mo ago
is the mongoclient for python compatible with the mongo server railway is running?
x4zx
x4zxOP14mo ago
How do you test it?
Brody
Brody14mo ago
check the version railway uses and then check the docs for your python mongo client
x4zx
x4zxOP14mo ago
I get a strange error when I try to run a separate class file for the database, maybe the reason is in it?
Traceback (most recent call last):
File "F:\Projects\instaview\utils\db.py", line 2, in <module>
from pymongo import MongoClient
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\__init__.py", line 92, in <module>
from pymongo.mongo_client import MongoClient
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\mongo_client.py", line 66, in <module>
from pymongo import (
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\uri_parser.py", line 46, in <module>
from pymongo.srv_resolver import _HAVE_DNSPYTHON, _SrvResolver
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\srv_resolver.py", line 23, in <module>
from dns import resolver
File "F:\Projects\instaview\venv\Lib\site-packages\dns\resolver.py", line 30, in <module>
import dns._ddr
File "F:\Projects\instaview\venv\Lib\site-packages\dns\_ddr.py", line 12, in <module>
import dns.nameserver
File "F:\Projects\instaview\venv\Lib\site-packages\dns\nameserver.py", line 5, in <module>
import dns.asyncquery
File "F:\Projects\instaview\venv\Lib\site-packages\dns\asyncquery.py", line 38, in <module>
from dns.query import (
File "F:\Projects\instaview\venv\Lib\site-packages\dns\query.py", line 130, in <module>
class _HTTPTransport(httpx.HTTPTransport):
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'httpx' has no attribute 'HTTPTransport'
Traceback (most recent call last):
File "F:\Projects\instaview\utils\db.py", line 2, in <module>
from pymongo import MongoClient
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\__init__.py", line 92, in <module>
from pymongo.mongo_client import MongoClient
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\mongo_client.py", line 66, in <module>
from pymongo import (
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\uri_parser.py", line 46, in <module>
from pymongo.srv_resolver import _HAVE_DNSPYTHON, _SrvResolver
File "F:\Projects\instaview\venv\Lib\site-packages\pymongo\srv_resolver.py", line 23, in <module>
from dns import resolver
File "F:\Projects\instaview\venv\Lib\site-packages\dns\resolver.py", line 30, in <module>
import dns._ddr
File "F:\Projects\instaview\venv\Lib\site-packages\dns\_ddr.py", line 12, in <module>
import dns.nameserver
File "F:\Projects\instaview\venv\Lib\site-packages\dns\nameserver.py", line 5, in <module>
import dns.asyncquery
File "F:\Projects\instaview\venv\Lib\site-packages\dns\asyncquery.py", line 38, in <module>
from dns.query import (
File "F:\Projects\instaview\venv\Lib\site-packages\dns\query.py", line 130, in <module>
class _HTTPTransport(httpx.HTTPTransport):
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'httpx' has no attribute 'HTTPTransport'
from os import getenv
from pymongo import MongoClient

from dotenv import load_dotenv
load_dotenv()

mongo_url = getenv('MONGO_URL')

class Database:
def __init__(self):
print(mongo_url)
self.client = MongoClient(mongo_url)
self._users = self.client.follow.users

@property
def users(self):
return self._users

@property
def users_data(self):
return self._users.find({})

@property
def instagram_ids(self):
return [user['instagram_id'] for user in self._users]

def find_user_by_id(self, identifier: str) -> dict:
user = self._users.find_one({'instagram_id': identifier})
return user or {}

def find_user_by_username(self, username: str) -> dict:
user = self._users.find_one({'tiktok': username})
return user or {}

def push_processed_via_identifier(self, identifier: str, media_id: int):
self._users.update_one(
{'instagram_id': identifier}, {'$push': {'processed': int(media_id)}})

def push_processed_via_username(self, username: str, media_id: int):
self._users.update_one(
{'tiktok': username}, {'$push': {'processed': int(media_id)}})


db = Database()
print(db.users_data)
from os import getenv
from pymongo import MongoClient

from dotenv import load_dotenv
load_dotenv()

mongo_url = getenv('MONGO_URL')

class Database:
def __init__(self):
print(mongo_url)
self.client = MongoClient(mongo_url)
self._users = self.client.follow.users

@property
def users(self):
return self._users

@property
def users_data(self):
return self._users.find({})

@property
def instagram_ids(self):
return [user['instagram_id'] for user in self._users]

def find_user_by_id(self, identifier: str) -> dict:
user = self._users.find_one({'instagram_id': identifier})
return user or {}

def find_user_by_username(self, username: str) -> dict:
user = self._users.find_one({'tiktok': username})
return user or {}

def push_processed_via_identifier(self, identifier: str, media_id: int):
self._users.update_one(
{'instagram_id': identifier}, {'$push': {'processed': int(media_id)}})

def push_processed_via_username(self, username: str, media_id: int):
self._users.update_one(
{'tiktok': username}, {'$push': {'processed': int(media_id)}})


db = Database()
print(db.users_data)
Brody
Brody14mo ago
that would be a code issue but please make sure mongoclient is compatible with the mongo server railway is running
x4zx
x4zxOP14mo ago
pymongo==4.5.0 and for the version on the server, is it to look somewhere in the settings?
No description
Brody
Brody14mo ago
looks like that uses mongo 7
x4zx
x4zxOP14mo ago
So they're a match? I can send you a link to connect to the database for the test if you need it
Brody
Brody14mo ago
please check to make sure pymongo 4.5.0 is compatible with mongodb 7.0
x4zx
x4zxOP14mo ago
No description
Brody
Brody14mo ago
what is that is this an AI answer?
x4zx
x4zxOP14mo ago
yep
Brody
Brody14mo ago
please don't rely on that, go read the pymongo docs
x4zx
x4zxOP14mo ago
No description
Brody
Brody14mo ago
perfect this is just seeming like a code issue at this point this issue wouldn't be isolated to the railway environment, please do research on this issue
x4zx
x4zxOP14mo ago
I also tried connecting via code to my mongodb cluster created via mongo atlas and connected successfully
Brody
Brody14mo ago
I'm sorry but code issues are a bit out of the scope of these help threads
Want results from more Discord servers?
Add your server