PyMongo Mongodb SSL Error or bad Authentification - python

I'm trying to use a mongo database I created but get an error I can't get rid of.
This is my code:
If I just print collection it works fine
from pymongo import MongoClient
import ssl
client = MongoClient("mongodb+srv://HugoAdmin:<XXXXXXXXXXX>#personalsite-3gjka.mongodb.net/test?retryWrites=true&w=majority")
db = client.test
db = client['Site']
collection = db['BlogPosts']
print(collection)
post = {"_id": 0, "author": "Hugo Joncour", "date": "25/03/2020"}
#collection.insert_one(post)
I get:
➜ webportfolio git:(master) ✗ Python3.6 mongo.py
Collection(Database(MongoClient(host=['personalsite-shard-00-01-3gjka.mongodb.net:27017', 'personalsite-shard-00-00-3gjka.mongodb.net:27017', 'personalsite-shard-00-02-3gjka.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='PersonalSite-shard-0', ssl=True), 'Site'), 'BlogPosts')
but if I want to insert post:
from pymongo import MongoClient
import ssl
client = MongoClient("mongodb+srv://HugoAdmin:<yvctrd6F7GUYBVYT>#personalsite-3gjka.mongodb.net/test?retryWrites=true&w=majority")
db = client.test
db = client['Site']
collection = db['BlogPosts']
#print(collection)
post = {"_id": 0, "author": "Hugo Joncour", "date": "25/03/2020"}
collection.insert_one(post)
I get:
➜ webportfolio git:(master) ✗ Python3.6 mongo.py
Traceback (most recent call last):
File "mongo.py", line 15, in <module>
collection.insert_one(post)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 698, in insert_one
session=session),
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 612, in _insert
bypass_doc_val, session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 600, in _insert_one
acknowledged, _insert_command, session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1490, in _retryable_write
with self._tmp_session(session) as s:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1823, in _tmp_session
s = self._ensure_session(session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1810, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1763, in __start_session
server_session = self._get_server_session()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1796, in _get_server_session
return self._topology.get_server_session()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/topology.py", line 490, in get_server_session
None)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/topology.py", line 209, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: personalsite-shard-00-00-3gjka.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841),SSL handshake failed: personalsite-shard-00-02-3gjka.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841),SSL handshake failed: personalsite-shard-00-01-3gjka.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)
I tried this https://api.mongodb.com/python/current/examples/tls.html
by adding " ssl=True, ssl_cert_reqs=ssl.CERT_NONE " in MongoClient() but I then get:
➜ webportfolio git:(master) ✗ Python3.6 mongo.py
Traceback (most recent call last):
File "mongo.py", line 15, in <module>
collection.insert_one(post)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 698, in insert_one
session=session),
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 612, in _insert
bypass_doc_val, session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 600, in _insert_one
acknowledged, _insert_command, session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1491, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1377, in _retry_with_session
with self._get_socket(server, session) as sock_info:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1222, in _get_socket
self.__all_credentials, checkout=exhaust) as sock_info:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 1138, in get_socket
sock_info.check_auth(all_credentials)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 712, in check_auth
auth.authenticate(credentials, self)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/auth.py", line 564, in authenticate
auth_func(credentials, sock_info)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/auth.py", line 539, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/auth.py", line 301, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 613, in command
user_fields=user_fields)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/network.py", line 167, in command
parse_write_concern_error=parse_write_concern_error)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/helpers.py", line 159, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: bad auth Authentication failed.
Any idea on how to solve this ?

Related

IndexError: pop from an empty deque while using pymongo

I'm trying to learn how to use mongo and got this error. The password is meant to start with an exclamation mark, but I change the actual password. Here's the code and error:
import pymongo
from pymongo import MongoClient
import dns.resolver
dns.resolver.default_resolver=dns.resolver.Resolver(configure=False)
dns.resolver.default_resolver.nameservers=['8.8.8.8']
cluster = pymongo.MongoClient("mongodb+srv://gabriel:%33%password#cluster1.ez4er.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
db = cluster["gabdatabase"]
collection = db["learningmongo"]
print(cluster.list_database_names())
Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 15, in <module>
collection.insert_one(post)
File "/usr/local/lib/python3.9/site-packages/pymongo/collection.py", line 705, in insert_one
self._insert(document,
File "/usr/local/lib/python3.9/site-packages/pymongo/collection.py", line 620, in _insert
return self._insert_one(
File "/usr/local/lib/python3.9/site-packages/pymongo/collection.py", line 609, in _insert_one
self.__database.client._retryable_write(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1462, in _retry_internal
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "/usr/local/lib/python3.9/site-packages/pymongo/network.py", line 158, in command
helpers._check_command_response(
File "/usr/local/lib/python3.9/site-packages/pymongo/helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 13, in <module>
print(cluster.list_database_names())
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2037, in list_database_names
for doc in self.list_databases(session, nameOnly=True)]
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2018, in list_databases
res = admin._retryable_read_command(cmd, session=session)
File "/usr/local/lib/python3.9/site-packages/pymongo/database.py", line 770, in _retryable_read_command
return self.__client._retryable_read(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1518, in _retryable_read
with self._secondaryok_for_server(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "/usr/local/lib/python3.9/site-packages/pymongo/network.py", line 158, in command
helpers._check_command_response(
File "/usr/local/lib/python3.9/site-packages/pymongo/helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 13, in <module>
print(cluster.list_database_names())
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2037, in list_database_names
for doc in self.list_databases(session, nameOnly=True)]
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2018, in list_databases
res = admin._retryable_read_command(cmd, session=session)
File "/usr/local/lib/python3.9/site-packages/pymongo/database.py", line 770, in _retryable_read_command
return self.__client._retryable_read(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1518, in _retryable_read
with self._secondaryok_for_server(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "/usr/local/lib/python3.9/site-packages/pymongo/network.py", line 158, in command
helpers._check_command_response(
File "/usr/local/lib/python3.9/site-packages/pymongo/helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 13, in <module>
print(cluster.list_database_names())
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2037, in list_database_names
for doc in self.list_databases(session, nameOnly=True)]
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2018, in list_databases
res = admin._retryable_read_command(cmd, session=session)
File "/usr/local/lib/python3.9/site-packages/pymongo/database.py", line 770, in _retryable_read_command
return self.__client._retryable_read(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1518, in _retryable_read
with self._secondaryok_for_server(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "/usr/local/lib/python3.9/site-packages/pymongo/network.py", line 158, in command
helpers._check_command_response(
File "/usr/local/lib/python3.9/site-packages/pymongo/helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 13, in <module>
print(cluster.list_database_names())
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2037, in list_database_names
for doc in self.list_databases(session, nameOnly=True)]
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2018, in list_databases
res = admin._retryable_read_command(cmd, session=session)
File "/usr/local/lib/python3.9/site-packages/pymongo/database.py", line 770, in _retryable_read_command
return self.__client._retryable_read(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1518, in _retryable_read
with self._secondaryok_for_server(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "/usr/local/lib/python3.9/site-packages/pymongo/network.py", line 158, in command
helpers._check_command_response(
File "/usr/local/lib/python3.9/site-packages/pymongo/helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 13, in <module>
print(cluster.list_database_names())
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2037, in list_database_names
for doc in self.list_databases(session, nameOnly=True)]
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2018, in list_databases
res = admin._retryable_read_command(cmd, session=session)
File "/usr/local/lib/python3.9/site-packages/pymongo/database.py", line 770, in _retryable_read_command
return self.__client._retryable_read(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1518, in _retryable_read
with self._secondaryok_for_server(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "/usr/local/lib/python3.9/site-packages/pymongo/network.py", line 158, in command
helpers._check_command_response(
File "/usr/local/lib/python3.9/site-packages/pymongo/helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop % /usr/local/bin/python /Users/Gu/Desktop/python/py2.py
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Gu/Desktop/python/py2.py", line 13, in <module>
print(cluster.list_database_names())
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2037, in list_database_names
for doc in self.list_databases(session, nameOnly=True)]
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 2018, in list_databases
res = admin._retryable_read_command(cmd, session=session)
File "/usr/local/lib/python3.9/site-packages/pymongo/database.py", line 770, in _retryable_read_command
return self.__client._retryable_read(
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1518, in _retryable_read
with self._secondaryok_for_server(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 820, in check_auth
self.authenticate(credentials)
File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python3.9/site-packages/pymongo/auth.py", line 590, in _authenticate_default
return
with server.get_socket(
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Gu#21emashmore21-971 Desktop %

ServerSelectionTimeoutError when saving documents with MongoClient using VPN, Authentication error without

I was able to save information in my MongoDB database. But now I have a pymongo.errors.ServerSelectionTimeoutError. Indeed with this code:
>>> db_url = "mongodb+srv://USER:PASSWORD#cluster0.n2hnd.mongodb.net/ifresearch?retryWrites=true&w=majority"
>>> client = pymongo.MongoClient(db_url)
>>> db = client.ifresearch
>>> collection = db.sephora
>>> collection.insert_one({'artist':'lasKetchup'})
I have:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\collection.py", line 701, in insert_one
session=session),
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\collection.py", line 615, in _insert
bypass_doc_val, session)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\collection.py", line 603, in _insert_one
acknowledged, _insert_command, session)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1497, in _retryable_write
with self._tmp_session(session) as s:
File "C:\Python36\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1829, in _tmp_session
s = self._ensure_session(session)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1816, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1766, in __start_session
server_session = self._get_server_session()
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1802, in _get_server_session
return self._topology.get_server_session()
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\topology.py", line 493, in get_server_session
None)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\topology.py", line 217, in _select_servers_loop
(self._error_message(selector), timeout, self.description))
pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-01.n2hnd.mongodb.net:27017: timed out,cluster0-shard-00-02.n2hnd.mongodb.net:27017: timed out,cluster0-
shard-00-00.n2hnd.mongodb.net:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 5fc9046a82506099b0f9a9bb, topology_type: ReplicaSetNoPri
mary, servers: [<ServerDescription ('cluster0-shard-00-00.n2hnd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cluster0-shard-00-00.n2hn
d.mongodb.net:27017: timed out',)>, <ServerDescription ('cluster0-shard-00-01.n2hnd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('clust
er0-shard-00-01.n2hnd.mongodb.net:27017: timed out',)>, <ServerDescription ('cluster0-shard-00-02.n2hnd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=N
etworkTimeout('cluster0-shard-00-02.n2hnd.mongodb.net:27017: timed out',)>]>
The function in the Pipeline class in pipeline.py is
def save_in_mongo(self, url, db, collection, perfume):
client = pymongo.MongoClient(url)
db = client[db]
collection = db[collection]
collection.insert_one(perfume)
The network access is open to all urls:
0.0.0.0/0 (includes your current IP address)
I use the following pymongo version
>>> pymongo.__version__
'3.11.0'
And I use a VPN, when I don't usse it I have the following OperationFailure related to authenticaiton:
>>> db_url = "mongodb+srv://USER:PASSWORD#cluster0.n2hnd.mongodb.net/ifresearch?retryWrites=true&w=majority"
>>> client = pymongo.MongoClient(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'url' is not defined
>>> client = pymongo.MongoClient(db_url)
>>> db = client.ifresearch
>>> collection = db.sephora
>>> collection.insert_one({'perfume':'zboule'})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\collection.py", line 701, in insert_one
session=session),
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\collection.py", line 615, in _insert
bypass_doc_val, session)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\collection.py", line 603, in _insert_one
acknowledged, _insert_command, session)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1498, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1384, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1408, in _retry_internal
with self._get_socket(server, session) as sock_info:
File "C:\Python36\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\mongo_client.py", line 1247, in _get_socket
self.__all_credentials, checkout=exhaust) as sock_info:
File "C:\Python36\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\pool.py", line 1225, in get_socket
sock_info = self._get_socket(all_credentials)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\pool.py", line 1279, in _get_socket
sock_info.check_auth(all_credentials)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\pool.py", line 793, in check_auth
self.authenticate(credentials)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\pool.py", line 810, in authenticate
auth.authenticate(credentials, self)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\auth.py", line 673, in authenticate
auth_func(credentials, sock_info)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\auth.py", line 591, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\pool.py", line 694, in command
exhaust_allowed=exhaust_allowed)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\network.py", line 162, in command
parse_write_concern_error=parse_write_concern_error)
File "C:\Users\antoi\Documents\Programming\Learning\DataScience\scr_env\lib\site-packages\pymongo\helpers.py", line 168, in _check_command_response
max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'A
tlasError'}

pymongo.errors.ServerSelectionTimeoutError

What could possibly be the reason of this error? I am using a ubuntu guest server in a windows 10 host system
The entire error is as follows:
` File "train_data.py", line 36, in <module>
update_database.insert_features(features)
File "/pupyl/preprocessing_data/update_database_with_features.py", line 59, in insert_features
self.db_operation.insert_record(records, "train")
File "/pupyl/database_client/database_operations.py", line 33, in insert_record
self.db.train.insert(record)
File "/usr/local/lib/python3.6/site-packages/pymongo/collection.py", line 3161, in insert
check_keys, manipulate, write_concern)
File "/usr/local/lib/python3.6/site-packages/pymongo/collection.py", line 607, in _insert
bypass_doc_val, session)
File "/usr/local/lib/python3.6/site-packages/pymongo/collection.py", line 595, in _insert_one
acknowledged, _insert_command, session)
File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1242, in _retryable_write
with self._tmp_session(session) as s:
File "/usr/local/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1571, in _tmp_session
s = self._ensure_session(session)
File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1558, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1511, in __start_session
server_session = self._get_server_session()
File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1544, in _get_server_session
return self._topology.get_server_session()
File "/usr/local/lib/python3.6/site-packages/pymongo/topology.py", line 427, in get_server_session
None)
File "/usr/local/lib/python3.6/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
`
train_data.py is as follows, if that helps:
features: Tuple[List[str], List[str], List[str], List[bool], List[str]] = \
extract_features.separation_of_features(parsed_json)
update_database.insert_features(features)
seems like your application is not being able to connect to database, verify if the database is actually running on localhost:27017 and accepting connections
ps: try connecting with mongoshell

Mongodb crashes when the same collection in accessed by two different python script using pymongo

I have two python scripts, currentdataupload.py and productioncount.py on my Ubuntu server. currentdataupload.py uploads dummy current data and productioncount.py accesses that data to do some calculations. The code runs perfectly in other scenarios without disrupting the MongoDB, but when I run both of these codes simultaneously using nohup after a few seconds it exits the mongoDB service and is no longer able to upload or retrieve data. I would like to know if I am doing the entire process the right way or I am messing up somewhere big time.
Error log
Traceback (most recent call last):
File "/python_codes/currentdataupload.py", line 38, in <module>
result = posts.insert_one(post_data)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 630, in insert_one
bypass_doc_val=bypass_document_validation),
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 535, in _insert
check_keys, manipulate, write_concern, op_id, bypass_doc_val)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 516, in _insert_one
check_keys=check_keys)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 244, in command
self._raise_connection_failure(error)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 372, in _raise_connection_failure
raise error
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 239, in command
read_concern)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/network.py", line 96, in command
response = receive_message(sock, 1, request_id)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/network.py", line 123, in receive_message
header = _receive_data_on_socket(sock, 16)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/network.py", line 161, in _receive_data_on_socket
raise AutoReconnect("connection closed")
pymongo.errors.AutoReconnect: connection closed
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 543, in connect
sock = _configured_socket(self.address, self.opts)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 452, in _configured_socket
sock = _create_connection(address, options)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 436, in _create_connection
raise err
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 429, in _create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/python_codes/productioncount.py", line 267, in <module>
result = col2.find_one({"date": date, "machine": machine})
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 1014, in find_one
for result in cursor.limit(-1):
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/cursor.py", line 1090, in next
if len(self.__data) or self._refresh():
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/cursor.py", line 1012, in _refresh
self.__read_concern))
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/cursor.py", line 850, in __send_message
**kwargs)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/mongo_client.py", line 844, in _send_message_with_response
exhaust)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/mongo_client.py", line 855, in _reset_on_error
return func(*args, **kwargs)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/server.py", line 99, in send_message_with_response
with self.get_socket(all_credentials, exhaust) as sock_info:
File "/root/anaconda3/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/server.py", line 163, in get_socket
with self.pool.get_socket(all_credentials, checkout) as sock_info:
File "/root/anaconda3/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 582, in get_socket
sock_info = self._get_socket_no_auth()
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 628, in _get_socket_no_auth
sock_info = self._check(sock_info)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 682, in _check
return self.connect()
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 555, in connect
_raise_connection_failure(self.address, error)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 65, in _raise_connection_failure
raise AutoReconnect(msg)
pymongo.errors.AutoReconnect: localhost:27017: [Errno 111] Connection refused
MongoDB shouldn't crash. Please file a bug report, including the Python script you run and a complete MongoDB logfile, at jira.mongodb.org.

Celery throwing long error message

I'm trying to run the starter code for celery on their website (http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html), and I'm running an instance of a RabbitMQ server in the background. However, I'm getting a long error message:
>>> from celery import Celery
>>> app = Celery('tasks', broker='pyamqp://guest#localhost//')
>>> #app.task
... def add(x, y):
... return x + y
...
>>>
>>> add.delay(4, 4)
Traceback (most recent call last):
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\utils\functional.py", line 36, in __call__
return self.__value__
AttributeError: 'ChannelPromise' object has no attribute '__value__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 494, in _ensured
return fun(*args, **kwargs)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\messaging.py", line 187, in _publish
channel = self.channel
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\messaging.py", line 209, in _get_channel
channel = self._channel = channel()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\utils\functional.py", line 38, in __call__
value = self.__value__ = self.__contract__()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\messaging.py", line 224, in <lambda>
channel = ChannelPromise(lambda: connection.default_channel)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 819, in default_channel
self.connection
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 802, in connection
self._connection = self._establish_connection()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\transport\pyamqp.py", line 130, in establish_connection
conn.connect()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\connection.py", line 294, in connect
self.transport.connect()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 122, in connect
self.socket_settings, self.read_timeout, self.write_timeout,
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 174, in _init_socket
self._set_socket_options(socket_settings)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 204, in _set_socket_options
self.sock.setsockopt(SOL_TCP, opt, val)
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 414, in _reraise_as_library_errors
yield
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 515, in _ensured
reraise_as_library_errors=False,
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 405, in ensure_connection
callback)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\utils\functional.py", line 333, in retry_over_time
return fun(*args, **kwargs)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 261, in connect
return self.connection
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 802, in connection
self._connection = self._establish_connection()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\transport\pyamqp.py", line 130, in establish_connection
conn.connect()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\connection.py", line 294, in connect
self.transport.connect()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 122, in connect
self.socket_settings, self.read_timeout, self.write_timeout,
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 174, in _init_socket
self._set_socket_options(socket_settings)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 204, in _set_socket_options
self.sock.setsockopt(SOL_TCP, opt, val)
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alexander\Anaconda3\lib\site-packages\celery\app\task.py", line 412, in delay
return self.apply_async(args, kwargs)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\celery\app\task.py", line 535, in apply_async
**options
File "C:\Users\Alexander\Anaconda3\lib\site-packages\celery\app\base.py", line 737, in send_task
amqp.send_task_message(P, name, message, **options)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\celery\app\amqp.py", line 558, in send_task_message
**properties
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\messaging.py", line 181, in publish
exchange_name, declare,
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 527, in _ensured
errback and errback(exc, 0)
File "C:\Users\Alexander\Anaconda3\lib\contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 419, in _reraise_as_library_errors
sys.exc_info()[2])
File "C:\Users\Alexander\Anaconda3\lib\site-packages\vine\five.py", line 175, in reraise
raise value.with_traceback(tb)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 414, in _reraise_as_library_errors
yield
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 515, in _ensured
reraise_as_library_errors=False,
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 405, in ensure_connection
callback)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\utils\functional.py", line 333, in retry_over_time
return fun(*args, **kwargs)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 261, in connect
return self.connection
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 802, in connection
self._connection = self._establish_connection()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\connection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\kombu\transport\pyamqp.py", line 130, in establish_connection
conn.connect()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\connection.py", line 294, in connect
self.transport.connect()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 122, in connect
self.socket_settings, self.read_timeout, self.write_timeout,
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 174, in _init_socket
self._set_socket_options(socket_settings)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\amqp\transport.py", line 204, in _set_socket_options
self.sock.setsockopt(SOL_TCP, opt, val)
kombu.exceptions.OperationalError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
There is an open issue on github where the same OS-error has been seen:
https://github.com/celery/py-amqp/issues/130
Someone suggested in the comments on the issue that it is temporarily resolved by downgrading the version of amqp to 2.1.3
Steps to take in order to downgrade:
Uninstall amqp using $ pip uninstall amqp.
Install amqp using $ pip install -Iv amqp==2.1.3.

Categories

Resources