a year ago
I have deployed a new version to my railway server, I didn't change anything related to my mongodb connection yet now my server is crashing and it is displaying this error, i am using Gunicorn with python flask, it runs perfectly on local with the same command as the one in the server
0 Replies
a year ago
is this a mongodb hosted on railway, or elsewhere, like atlas
a year ago
have you whitelisted all ip ranges? 0.0.0.0/0
a year ago
please send a screenshot of that setting too
a year ago
is that 0.0.0.0/0
network access rule set on the correct database?
a year ago
okay, can you show me the client code that connects to the database
from pymongo import MongoClient
import certifi
from models.config import MONGO_DB_URL
class MongoDB:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance.client = MongoClient(MONGO_DB_URL)
cls._instance.db = cls._instance.client["bookitspot"]
return cls._instance.db
db = MongoDB()
MONGO_DB_URL = "mongodb+srv://username:password@cluster/?retryWrites=true&w=majority"
a year ago
and where do you have that service variable set?
a year ago
both
my root folder is called v2
the connection url is inside: v2 -> models -> config.py
the db variable is set inside -> v2 -> models -> database -> db_connection.py
the code i sent for the connection is the whole db_connection.py file
this is how I grab that variable to use:
from models.database.db_connection import db
a year ago
so you are hardcoding the url?
a year ago
set it as a service variable
then read the variable from the environment in code
by any chance do you know how I would use it inside the code? ive never used smth like this and the example is for node js
a year ago
i saw that lol
a year ago
always a quick google away! 🙂
from pymongo import MongoClient
import certifi
# from models.config import MONGO_DB_URL
import os
class MongoDB:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
db_url = os.environ['DB_URL']
cls._instance.client = MongoClient(db_url)
cls._instance.db = cls._instance.client["bookitspot"]
return cls._instance.db
db = MongoDB()
a year ago
you have set it as a service variable?
a year ago
please do not use a shared variable for this
a year ago
show me the service variables please
a year ago
and you are sure that is set correctly?
a year ago
why not just run mongo on railway?
but it was working all the time, until today, my server was even running fine in the morning with the same setup
a year ago
my current thought process is that atlas has blocked the shared ip that you are trying to connect from
a year ago
im not talking about the access rules
a year ago
would you be interested in running a mongo database on railway?
a year ago
unfortunaly it doesn’t seem like its going to work out
i feel like there has to be a way to make it work again, since its been working for over a month
a year ago
you could get in contact with atlas
ok yh ive opened a ticket with them to see what they say, its so strange tbh as there is nothing online abt the error too
Locally im using version 2.4.2, but even on local when I update it to latest version it gives me the same error
Now, I set the version for dnspython==2.4.2 on my requiremenets.txt file but when I check the build logs on the server it's installing the latest version
10 16.45 Successfully installed Flask-3.0.0 Flask-Cors-4.0.0 Jinja2-3.1.2 MarkupSafe-2.1.3 PyJWT-2.8.0 Werkzeug-3.0.1 anyio-4.3.0 bcrypt-4.0.1 bidict-0.23.1 blinker-1.7.0 certifi-2023.7.22 cffi-1.16.0 charset-normalizer-3.3.2 click-8.1.7 cloudinary-1.38.0 cryptography-41.0.5 dnspython-2.6.1 eventlet-0.34.2 exceptiongroup-1.2.0 flask_socketio-5.3.6 gevent-24.2.1 gevent-websocket-0.10.1 greenlet-3.0.3 gunicorn-21.2.0 h11-0.14.0 h2-4.1.0 hpack-4.0.0 httpcore-1.0.4 httpx-0.26.0 hyperframe-6.0.1 idna-3.4 importlib-metadata-7.0.1 itsdangerous-2.1.2 packaging-23.2 pycparser-2.21 pymongo-4.6.0 python-dateutil-2.8.2 python-engineio-4.9.0 python-socketio-5.11.1 requests-2.31.0 simple-websocket-1.0.0 six-1.16.0 sniffio-1.3.1 typing-extensions-4.10.0 urllib3-2.0.7 wsproto-1.2.0 zipp-3.17.0 zope.event-5.0 zope.interface-6.2
How can I change the version since I thought it pulled from the requierements file?
a year ago
by specifying the wanted version in your requirements.txt
a year ago
you have a different version set elsewhere
a year ago
or you haven't pushed those changes
a year ago
interesting, well my apologies for sending you in the wrong direction, it was really looking like an IP ban from atlas
a year ago
I don't think there's anyone who could have helped with such an obscure cause of this issue
a year ago
but happy you found a solution!