Question: Can you fix the code in the image meant for Jupyter Notebook: It gives me the below output errors when I try to run the

Can you fix the code in the image meant for Jupyter Notebook:
It gives me the below output errors when I try to run the Python_Testing_Script:
---------------------------------------------------------------------------
OperationFailure Traceback (most recent call last)
Input In [1], in ()
5 # Test create method
6 data ={"Age": "2 years", "Type": "Dog"}
---->7 if shelter.create(data):
8 print("Animal has been added.")
9 else:
File ~/Documents/animal_shelter.py:23, in AnimalShelter.create(self, data)
21 def create(self, data):
22 if data:
--->23 self.database.animals.insert_one(data)
24 return True
25 else:
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/collection.py:705, in Collection.insert_one(self, document, bypass_document_validation, session)
701 document["_id"]= ObjectId()
703 write_concern = self._write_concern_for(session)
704 return InsertOneResult(
-->705 self._insert(document,
706 write_concern=write_concern,
707 bypass_doc_val=bypass_document_validation,
708 session=session),
709 write_concern.acknowledged)
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/collection.py:620, in Collection._insert(self, docs, ordered, check_keys, manipulate, write_concern, op_id, bypass_doc_val, session)
618"""Internal insert helper."""
619 if isinstance(docs, abc.Mapping):
-->620 return self._insert_one(
621 docs, ordered, check_keys, manipulate, write_concern, op_id,
622 bypass_doc_val, session)
624 ids =[]
626 if manipulate:
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/collection.py:609, in Collection._insert_one(self, doc, ordered, check_keys, manipulate, write_concern, op_id, bypass_doc_val, session)
597 result = sock_info.command(
598 self.__database.name,
599 command,
(...)
604 client=self.__database.client,
605 retryable_write=retryable_write)
607_check_write_command_response(result)
-->609 self.__database.client._retryable_write(
610 acknowledged, _insert_command, session)
612 if not isinstance(doc, RawBSONDocument):
613 return doc.get('_id')
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/mongo_client.py:1552, in MongoClient._retryable_write(self, retryable, func, session)
1550"""Internal retryable write helper."""
1551 with self._tmp_session(session) as s:
->1552 return self._retry_with_session(retryable, func, s, None)
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/mongo_client.py:1438, in MongoClient._retry_with_session(self, retryable, func, session, bulk)
1429"""Execute an operation with at most one consecutive retries
1430
1431 Returns func()'s return value on success. On error retries the same
(...)
1434 Re-raises any exception thrown by func().
1435"""
1436 retryable =(retryable and self.retry_writes
1437 and session and not session.in_transaction)
->1438 return self._retry_internal(retryable, func, session, bulk)
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/mongo_client.py:1470, in MongoClient._retry_internal(self, retryable, func, session, bulk)
1468 raise last_error
1469 retryable = False
->1470 return func(session, sock_info, retryable)
1471 except ServerSelectionTimeoutError:
1472 if is_retrying():
1473 # The application may think the write was never attempted
1474 # if we raise ServerSelectionTimeoutError on the retry
1475 # attempt. Raise the original exception instead.
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/collection.py:597, in Collection._insert_one.._insert_command(session, sock_info, retryable_write)
594 if bypass_doc_val and sock_info.max_wire_version >=4:
595 command['bypassDocumentValidation']= True
-->597 result = sock_info.command(
598 self.__database.name,
599 command,
600 write_concern=write_concern,
601 codec_options=self.__write_response_codec_options,
602 check_keys=check_keys,
603 session=session,
604 client=self.__database.client,
605 retryable_write=retryable_write)
607_check_write_command_response(result)
File /usr/local/anaconda/lib/python3.9/site-packages/pymongo/pool.py:710, in SocketInfo.command(self, dbname, spec, secondary_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, user_fields, exhaust_allowed)
708 self._raise_if_not_writable(unacknowledged)
709 try:
-->710 return command(self, dbname, spec, secondary_ok,
711 self.is_mongos
 Can you fix the code in the image meant for Jupyter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!