Forums

connection refuse atlas & pymongo

when im try to connect with my home pc its work fine! im trying to connect in pythonanywhere to atlas mongo cloud with pymongo but im keep getting this error

"pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-01-spxa1.mongodb.net:27017: [Errno 111] Connection refused,cluster0-shard-00-02-spxa1.mongodb.ne t:27017: [Errno 111] Connection refused,cluster0-shard-00-00-spxa1.mongodb.net:27017: [Errno 111] Connection refused"

my code:

import pymongo

def Func(database_name,collection_name):

    """ connect to mongodb and return database and collection"""


    ## ---- connect to mongo & create or switch databse ---- ##
    mongo = pymongo.MongoClient("mongodb+srv://<user>:<password>@cluster0-spxa1.mongodb.net/test?retryWrites=true&w=majority")
    database = mongo[database_name]

    ## ---- return collection ---- ##
    return database[collection_name]



Func("test","test").insert_one({"test":"1"})

Free users cannot make outgoing internet connections. You are restricted to a whitelist.

I was trying the same thing. To connect to a free Atlas Cluster offered by MongoDB. I realize you cannot get everything for free but maybe, just maybe, you could allow connections to these free MongoDB clusters. I will not be upset on you if you don't :)

Thank you again for allowing us to try some things out with the free tier.

That's not something that we're likely to do. Sorry.

I just came here after spending a bit debugging why I couldn't connect to mongo. Oof. I am disappointed.

I guess I get it. We all need to make money. If it's not going to change, it would be cool if this whitelisting restriction was more prominent. On the other hand, I guess that's on me for not reading the pricing chart carefully enough. I wouldn't have spent so much time here if I knew it wasn't going to work.

The whitelist is why we say "restricted outbound Internet access from your apps" in the description of free accounts. It's not so much a way of making money, it's more to stop us from getting taken down from the Internet due to network abuse. Originally we allowed unrestricted Internet access for free accounts, and we became swamped by hackers who were using us to hide their identities when they tried to hack into other people's sites.

Hello! I've checked the whitelist and .mongodb.net is listed, but I'm having the same error with a similar connection as the original post. This means that, although the domain is whitelisted, the "kind" of connection made by pymongo is restricted?

Mongo requires a non-http connection, so it will not work on a free account.

Hi, can we do this under the hacker plan?

Yes