I thought I could use Jupyter notebook from command line. though import pymongo is not giving error, any other command related to cursor is fiving error
############
import pymongo
uri = “mongodb+srv://m220-user:m220-pass@mflix-XXXXmongodb.net/test”
client = pymongo.MongoClient(uri)
m220 = client.m220
movies = m220.movies
No issues when ran
cursor = movies.find( { “cast”: “Salma Hayek” }, { “title”: 1 } )
print(dumps(cursor, indent=2))
OperationFailure Traceback (most recent call last)
in ()
1 cursor = movies.find( { “cast”: “Salma Hayek” }, { “title”: 1 } )
----> 2 print(dumps(cursor, indent=2))
C:\new\Software\Anaconda3\lib\site-packages\bson\json_util.py in dumps(obj, *args, **kwargs)
406 “”"
407 json_options = kwargs.pop(“json_options”, DEFAULT_JSON_OPTIONS)
–> 408 return json.dumps(_json_convert(obj, json_options), *args, **kwargs)
409
410
C:\new\Software\Anaconda3\lib\site-packages\bson\json_util.py in _json_convert(obj, json_options)
447 for k, v in iteritems(obj)))
448 elif hasattr(obj, ‘iter’) and not isinstance(obj, (text_type, bytes)):
–> 449 return list((_json_convert(v, json_options) for v in obj))
450 try:
451 return default(obj, json_options)
C:\new\Software\Anaconda3\lib\site-packages\bson\json_util.py in (.0)
447 for k, v in iteritems(obj)))
448 elif hasattr(obj, ‘iter’) and not isinstance(obj, (text_type, bytes)):
–> 449 return list((_json_convert(v, json_options) for v in obj))
450 try:
451 return default(obj, json_options)
C:\new\Software\Anaconda3\lib\site-packages\pymongo\cursor.py in next(self)
1187 if self.__empty:
1188 raise StopIteration
-> 1189 if len(self.__data) or self._refresh():
1190 if self.__manipulate:
1191 _db = self.__collection.database
C:\new\Software\Anaconda3\lib\site-packages\pymongo\cursor.py in _refresh(self)
1102 self.__session,
1103 self.__collection.database.client)
-> 1104 self.__send_message(q)
1105 elif self.__id: # Get More
1106 if self.__limit:
C:\new\Software\Anaconda3\lib\site-packages\pymongo\cursor.py in __send_message(self, operation)
929 try:
930 response = client._send_message_with_response(
–> 931 operation, exhaust=self.__exhaust, address=self.__address)
932 self.__address = response.address
933 if self.__exhaust:
C:\new\Software\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _send_message_with_response(self, operation, exhaust, address)
1143 self.__all_credentials,
1144 self._event_listeners,
-> 1145 exhaust)
1146
1147 def _reset_on_error(self, server, func, *args, **kwargs):
C:\new\Software\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _reset_on_error(self, server, func, *args, **kwargs)
1154 “”"
1155 try:
-> 1156 return func(*args, **kwargs)
1157 except NetworkTimeout:
1158 # The socket has been closed. Don’t reset the server.
C:\new\Software\Anaconda3\lib\site-packages\pymongo\server.py in send_message_with_response(self, operation, set_slave_okay, all_credentials, listeners, exhaust)
83 It is returned along with its Pool in the Response.
84 “”"
—> 85 with self.get_socket(all_credentials, exhaust) as sock_info:
86
87 duration = None
C:\new\Software\Anaconda3\lib\contextlib.py in enter(self)
110 del self.args, self.kwds, self.func
111 try:
–> 112 return next(self.gen)
113 except StopIteration:
114 raise RuntimeError(“generator didn’t yield”) from None
C:\new\Software\Anaconda3\lib\site-packages\pymongo\pool.py in get_socket(self, all_credentials, checkout)
1004 sock_info = self._get_socket_no_auth()
1005 try:
-> 1006 sock_info.check_auth(all_credentials)
1007 yield sock_info
1008 except:
C:\new\Software\Anaconda3\lib\site-packages\pymongo\pool.py in check_auth(self, all_credentials)
675
676 for credentials in cached - authset:
–> 677 auth.authenticate(credentials, self)
678 self.authset.add(credentials)
679
C:\new\Software\Anaconda3\lib\site-packages\pymongo\auth.py in authenticate(credentials, sock_info)
540 mechanism = credentials.mechanism
541 auth_func = _AUTH_MAP.get(mechanism)
–> 542 auth_func(credentials, sock_info)
543
544
C:\new\Software\Anaconda3\lib\site-packages\pymongo\auth.py in _authenticate_default(credentials, sock_info)
515 return _authenticate_scram(credentials, sock_info, ‘SCRAM-SHA-256’)
516 else:
–> 517 return _authenticate_scram(credentials, sock_info, ‘SCRAM-SHA-1’)
518 elif sock_info.max_wire_version >= 3:
519 return _authenticate_scram(credentials, sock_info, ‘SCRAM-SHA-1’)
C:\new\Software\Anaconda3\lib\site-packages\pymongo\auth.py in _authenticate_scram(credentials, sock_info, mechanism)
243 (‘payload’, Binary(b"n," + first_bare)),
244 (‘autoAuthorize’, 1)])
–> 245 res = sock_info.command(source, cmd)
246
247 server_first = res[‘payload’]
C:\new\Software\Anaconda3\lib\site-packages\pymongo\pool.py in command(self, dbname, spec, slave_ok, read_preference, codec_options, check, allowable_errors, check_keys, read_concern, write_concern, parse_write_concern_error, collation, session, client, retryable_write, publish_events)
577 compression_ctx=self.compression_context,
578 use_op_msg=self.op_msg_enabled,
–> 579 unacknowledged=unacknowledged)
580 except OperationFailure:
581 raise
C:\new\Software\Anaconda3\lib\site-packages\pymongo\network.py in command(sock, dbname, spec, slave_ok, is_mongos, read_preference, codec_options, session, client, check, allowable_errors, address, check_keys, listeners, max_bson_size, read_concern, parse_write_concern_error, collation, compression_ctx, use_op_msg, unacknowledged)
148 helpers._check_command_response(
149 response_doc, None, allowable_errors,
–> 150 parse_write_concern_error=parse_write_concern_error)
151 except Exception as exc:
152 if publish:
C:\new\Software\Anaconda3\lib\site-packages\pymongo\helpers.py in _check_command_response(response, msg, allowable_errors, parse_write_concern_error)
153
154 msg = msg or “%s”
–> 155 raise OperationFailure(msg % errmsg, code, response)
156
157
OperationFailure: Authentication failed.
Not sure why this message comes when i try to do any thing with cursor or cursor printing.
OperationFailure: Authentication failed.
I appreciate any input