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:[email protected]/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:[email protected]/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'}