connection times out when trying to connect to mongodb atlas with python

2024/10/15 1:21:15

I'm trying to connect to my mongodb atlas cluster but i keep getting timed out as soon as i try to do something with my db.

The db i use was created in mongoshell and also the collection i checked their existence in mongodb compass

ERROR

pymongo.errors.ServerSelectionTimeoutError: projekt-shard-00-01-rk7ft.mongodb.net:27017: timed out,projekt-shard-00-00-rk7ft.mongodb.net:27017: timed out,projekt-shard-00-02-rk7ft.mongodb.net:27017: timed out

CODE

client = MongoClient("""mongodb://user:[email protected]:27017,projekt-shard-00-01-rk7ft.mongodb.net:27017,projekt-shard-00-02-rk7ft.mongodb.net:27017/projekt?ssl=true&replicaSet=projekt-shard-0&authSource=admin""")client.projekt.category.insert_one({type : "pants"}).inserted_id
Answer

SO the problem is with your IP Address,

  1. GO to the Network Access panel in MongoDB Atlas
  2. In the IP Access List section, you will find all your IP addresses
  3. Click on edit tab for the current IP address you are using
  4. There change the setting to ALLOW ACCESS FROM ANYWHERE

That's it, it will work!

https://en.xdnf.cn/q/69342.html

Related Q&A

Supervisor not working with Gunicorn + Flask

I am trying to run Gunicorn from Supervisor in an Ubuntu 12.04 system. Gunicorn runs a Flask app (simple REST web service tested with Flasks embedded server). I have installed Gunicorn by clonning GIT …

How to hash int/long using hashlib in Python?

Im developing a set of cryptographic algorithms / protocols for educational purposes. Specifically, I am currently working on OAEP encoding.OAEP involves use of cryptographic hash functions; therefore …

SQLAlchemy: Override relationship-defined order_by in a query

So, I have a model that is something like:class Foo(model):__tablename__ = "foo"id = Column(Integer, primary_key=True)data = relationship("FooData",cascade="all, delete-orphan&…

Toplevel in Tkinter: Prevent Two Windows from Opening

Say I have some simple code, like this:from Tkinter import * root = Tk() app = Toplevel(root) app.mainloop()This opens two windows: the Toplevel(root) window and the Tk() window. Is it possible to avoi…

Specify File path in tkinter File dialog

I have a file dialog to open a file, however, the file that I want to open is in a different directory than the program I wrote. The file dialog opens to the directory where I am. Is there a way to s…

Why does scipy linear interpolation run faster than nearest neighbor interpolation?

Ive written a routine that interpolates point data onto a regular grid. However, I find that scipys implementation of nearest neighbor interpolation performs almost twice as slow as the radial basis f…

How do I create a 404 page?

My application catches all url requests with an @app.route, but occasionally I bump into a bad url for which I have no matching jinja file (bu it does match an existing @app.route). So I want to redire…

Injecting pre-trained word2vec vectors into TensorFlow seq2seq

I was trying to inject pretrained word2vec vectors into existing tensorflow seq2seq model.Following this answer, I produced the following code. But it doesnt seem to improve performance as it should, a…

MySQL Stored Procedures, Pandas, and Use multi=True when executing multiple statements

Note - as MaxU suggested below, the problem is specific to mysql.connector and does not occur if you use pymysql. Hope this saves someone else some headachesUsing Python, Pandas, and mySQL and cannot…

How can I change the font size in GTK?

Is there an easy way to change the font size of text elements in GTK? Right now the best I can do is do set_markup on a label, with something silly like:lbl.set_markup("<span font_desc=Tahoma …