IndexError: pop from an empty deque while using pymongo - python
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 %
Related
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'}
Connecting to Google Cloud SQL Server from App Engine in the same project - Login timeout
I am using the sample code that google has provided on github: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/cloud-sql/sql-server/sqlalchemy I have created a Cloud SQL server on the project and when I run the main.py file from my local machine, the database gets updated OK. However, when I deploy the same code on Google App Engine, I get the following timeout error: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/gthread.py", line 271, in handle keepalive = self.handle_request(req, conn) File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/gthread.py", line 320, in handle_request respiter = self.wsgi(environ, resp.start_response) File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2464, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2450, in wsgi_app response = self.handle_exception(e) File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1867, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1945, in full_dispatch_request self.try_trigger_before_first_request_functions() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1993, in try_trigger_before_first_request_functions func() File "/app/main.py", line 116, in create_tables if not db.has_table("votes"): File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2331, in has_table return self.run_callable(self.dialect.has_table, table_name, schema) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2211, in run_callable with self._contextual_connect() as conn: File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2302, in _contextual_connect self._wrap_pool_connect(self.pool.connect, None), File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2339, in _wrap_pool_connect Connection._handle_dbapi_exception_noconnection( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1583, in _handle_dbapi_exception_noconnection util.raise_( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2336, in _wrap_pool_connect return fn() File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 364, in connect return _ConnectionFairy._checkout(self) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout fairy = _ConnectionRecord.checkout(pool) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 495, in checkout rec = pool._do_get() File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get self._dec_overflow() File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__ compat.raise_( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get return self._create_connection() File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection return _ConnectionRecord(self) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 440, in __init__ self.__connect(first_connect_check=True) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 661, in __connect pool.logger.debug("Error on connect(): %s", e) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__ compat.raise_( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 656, in __connect connection = pool._invoke_creator(self) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect return dialect.connect(*cargs, **cparams) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 493, in connect return self.dbapi.connect(*cargs, **cparams) sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
You need to configure your App Engine Flex service to connect to a Cloud SQL instance. In your app.yaml you need to set: beta_settings: cloud_sql_instances: INSTANCE_CONNECTION_NAME=tcp:PORT Where the INSTANCE_CONNECTION_NAME has the following structure: <project-name>:<region-name>:<instance-name> And when you connect, you should connect to 172.17.0.1:PORT where PORT is the port you specified in the app.yaml file
Connecting Flask To AWS RDS using Flask-SQLAlchemy
I have been trying to connect my aws RDS database instance to a flask application I have downloaded. I have been following https://medium.com/#rodkey/deploying-a-flask-application-on-aws-a72daba6bb80 and using the flask app on this github to connect to the database https://github.com/inkjet/flask-aws-tutorial. I have set the permissions on my RDS server correctly and have been using the following code to connect to the DB. # edit the URI below to add your RDS password and your AWS URL # The other elements are the same as used in the tutorial # format: (user):(password)#(db_identifier).amazonaws.com:3306/(db_name) SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{userName}:{password}#{endpoint}:3306/{dbName}' # Uncomment the line below if you want to work with a local DB #SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db' SQLALCHEMY_POOL_RECYCLE = 3600 WTF_CSRF_ENABLED = True I am still receiving a timeout error: {path_to_virt_env}/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py:834: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ' Traceback (most recent call last): File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/connections.py", line 583, in connect **kwargs) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 728, in create_connection raise err File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) socket.timeout: timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2345, in _wrap_pool_connect return fn() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 364, in connect return _ConnectionFairy._checkout(self) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout fairy = _ConnectionRecord.checkout(pool) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 495, in checkout rec = pool._do_get() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get self._dec_overflow() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__ exc_value, with_traceback=exc_tb, File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_ raise exception File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get return self._create_connection() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection return _ConnectionRecord(self) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 440, in __init__ self.__connect(first_connect_check=True) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 661, in __connect pool.logger.debug("Error on connect(): %s", e) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__ exc_value, with_traceback=exc_tb, File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_ raise exception File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 656, in __connect connection = pool._invoke_creator(self) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect return dialect.connect(*cargs, **cparams) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 490, in connect return self.dbapi.connect(*cargs, **cparams) File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect return Connection(*args, **kwargs) File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/connections.py", line 325, in __init__ self.connect() File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/connections.py", line 630, in connect raise exc pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '{endpoint}' (timed out)") The above exception was the direct cause of the following exception: Traceback (most recent call last): File "db_create.py", line 4, in <module> db.create_all() File "{path_to_virt_env}/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all self._execute_for_all_tables(app, bind, 'create_all') File "{path_to_virt_env}/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables op(bind=self.get_engine(app, bind), **extra) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/sql/schema.py", line 4465, in create_all ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2103, in _run_visitor with self._optional_conn_ctx_manager(connection) as conn: File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__ return next(self.gen) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2095, in _optional_conn_ctx_manager with self._contextual_connect() as conn: File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2311, in _contextual_connect self._wrap_pool_connect(self.pool.connect, None), File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2349, in _wrap_pool_connect e, dialect, self File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1591, in _handle_dbapi_exception_noconnection sqlalchemy_exception, with_traceback=exc_info[2], from_=e File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_ raise exception File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2345, in _wrap_pool_connect return fn() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 364, in connect return _ConnectionFairy._checkout(self) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout fairy = _ConnectionRecord.checkout(pool) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 495, in checkout rec = pool._do_get() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get self._dec_overflow() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__ exc_value, with_traceback=exc_tb, File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_ raise exception File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get return self._create_connection() File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection return _ConnectionRecord(self) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 440, in __init__ self.__connect(first_connect_check=True) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 661, in __connect pool.logger.debug("Error on connect(): %s", e) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__ exc_value, with_traceback=exc_tb, File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_ raise exception File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 656, in __connect connection = pool._invoke_creator(self) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect return dialect.connect(*cargs, **cparams) File "{path_to_virt_env}/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 490, in connect return self.dbapi.connect(*cargs, **cparams) File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect return Connection(*args, **kwargs) File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/connections.py", line 325, in __init__ self.connect() File "{path_to_virt_env}/lib/python3.7/site-packages/pymysql/connections.py", line 630, in connect raise exc sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '{endpoint}' (timed out)") (Background on this error at: http://sqlalche.me/e/e3q8 If any more information is needed, please let me know!
Based on the comments, the issue was that RDS's public accessibility setting was not enabled. The solution was to enable it.
PyMongo Mongodb SSL Error or bad Authentification
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 ?
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