8/19/2023 0 Comments Python ssh tunnel mongodb remotely![]() ![]() Python that you are using, you can just use the REST interface to ipify. If there is not a version of the ipify module that works with the version of Replacing the bits inside the s: import requests from th import HTTPDigestAuth from ipify import get_ip atlas_group_id = "" atlas_api_key_public = "" atlas_api_key_private = "" ip = get_ip () resp = requests. Install the ipify module and then use this, Nicolas Oteiza and modified by Amitoz Azad) will do that. The following code (based on code provided by Ipify service, which tells you what IP address yourĬode is using right now, to make your code automatically accesslist the IP it's The easiest, solution, though certainly not the most secure, is to accesslist theĬIDR 0.0.0.0/0, which is a "accesslist" containing every IP address on the Internet.Ī more secure solution is to use the MongoDB Atlas API to tell them about new IPĪddresses that they should allow to connect. Whether it's running in a website's code, or in a task, or in a console. To connect to your Mongo instance this can be a bit tricky on PythonAnywhere,īecause the precise IP address will depend on the time your code runs, and MongoDB Atlas requires you to provide the IP address of any code that is trying Accesslist your IP address for MongoDB Atlas ¶ This handles the bulk of the stuff that would otherwise be handled by Flask-PyMongo If you're just using the "raw" PyMongo API, there are a few extra parametersįor pymongo = 4: connectTimeoutMS = 30000, socketTimeoutMS = None, connect = False, maxPoolsize = 1 If you're connecting from a web app, and you're using Flask, we recommend thatĮxtension, which works well in a multiprocessing environment like websites To specify the server, the username and the password. If you're connecting from a console or a scheduled task, just use the regular There is a complete step-by-step tutorial on our blog. # Rest of file contains routes with calls to databaseĭoes anyone know why I am getting these errors? Thanks.We don't provide Mongo servers ourselves, so you'll need to get one from anĮxternal provider (many of our customers are using MongoDB Atlas).įor best performance, you should provision your server in the AWS us-east-1ĭatacenter if you're using our US-based site at or theĮu-central-1 datacenter if you're using our EU site at eu.īecause this will require non-HTTP external Internet access, And it's not a problem with the URI since I can log into a Mongo shell with it when the SSH connection is up.Īpp.config = os.environĪpp.config = Trueĭatabase.py from flask_pymongo import PyMongoįrontend = Blueprint('frontend', _name_) This leads me to believe that I am missing a step when connecting to the remote MongoDB. One last thing: I have not experienced any errors when trying to connect to the local MongoDB running in a local Docker container. (The previous error only happens when the local container is not running). This only happens if I have a Docker container with Mongo running on my local machine. : 127.0.0.1:9999: Connection refused, Timeout: 30s, Topology Description: ]>Īnother error I've been seeing is PyMongo authentication failed. PyMongo cannot seem to connect to the database (connection refused). The issue is when I try to run the Flask app. My Mongo URI is I tunnel the SSH connection to the server: ssh -L 9999:localhost:27017 -N I connect to a Mongo shell after tunneling the connection, it works as expected. The data that I need is from MongoDB, which is running on a Docker container on a server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |