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 PythonTestingScript:
OperationFailure Traceback most recent call last
Input In in
# Test create method
data Age: years", "Type": "Dog"
if shelter.createdata:
printAnimal has been added."
else:
File ~Documentsanimalshelter.py: in AnimalShelter.createself data
def createself data:
if data:
self.database.animals.insertonedata
return True
else:
File usrlocalanacondalibpythonsitepackagespymongocollectionpy: in Collection.insertoneself document, bypassdocumentvalidation, session
documentid ObjectId
writeconcern self.writeconcernforsession
return InsertOneResult
self.insertdocument
writeconcernwriteconcern,
bypassdocvalbypassdocumentvalidation,
sessionsession
writeconcern.acknowledged
File usrlocalanacondalibpythonsitepackagespymongocollectionpy: in Collection.insertself docs, ordered, checkkeys, manipulate, writeconcern, opid bypassdocval, session
Internal insert helper."""
if isinstancedocs abc.Mapping:
return self.insertone
docs, ordered, checkkeys, manipulate, writeconcern, opid
bypassdocval, session
ids
if manipulate:
File usrlocalanacondalibpythonsitepackagespymongocollectionpy: in Collection.insertoneself doc, ordered, checkkeys, manipulate, writeconcern, opid bypassdocval, session
result sockinfo.command
self.database.name,
command,
clientself.database.client,
retryablewriteretryablewrite
checkwritecommandresponseresult
self.database.client.retryablewrite
acknowledged, insertcommand, session
if not isinstancedoc RawBSONDocument:
return doc.getid
File usrlocalanacondalibpythonsitepackagespymongomongoclient.py: in MongoClient.retryablewriteself retryable, func, session
Internal retryable write helper."""
with self.tmpsessionsession as s:
return self.retrywithsessionretryable func, s None
File usrlocalanacondalibpythonsitepackagespymongomongoclient.py: in MongoClient.retrywithsessionself retryable, func, session, bulk
Execute an operation with at most one consecutive retries
Returns funcs return value on success. On error retries the same
Reraises any exception thrown by func
retryable retryable and self.retrywrites
and session and not session.intransaction
return self.retryinternalretryable func, session, bulk
File usrlocalanacondalibpythonsitepackagespymongomongoclient.py: in MongoClient.retryinternalself retryable, func, session, bulk
raise lasterror
retryable False
return funcsession sockinfo, retryable
except ServerSelectionTimeoutError:
if isretrying:
# The application may think the write was never attempted
# if we raise ServerSelectionTimeoutError on the retry
# attempt. Raise the original exception instead.
File usrlocalanacondalibpythonsitepackagespymongocollectionpy: in Collection.insertone..insertcommandsession sockinfo, retryablewrite
if bypassdocval and sockinfo.maxwireversion :
commandbypassDocumentValidation True
result sockinfo.command
self.database.name,
command,
writeconcernwriteconcern,
codecoptionsself.writeresponsecodecoptions,
checkkeyscheckkeys,
sessionsession,
clientself.database.client,
retryablewriteretryablewrite
checkwritecommandresponseresult
File usrlocalanacondalibpythonsitepackagespymongopoolpy: in SocketInfo.commandself dbname, spec, secondaryok readpreference, codecoptions, check, allowableerrors, checkkeys, readconcern, writeconcern, parsewriteconcernerror, collation, session, client, retryablewrite, publishevents, userfields, exhaustallowed
self.raiseifnotwritableunacknowledged
try:
return commandself dbname, spec, secondaryok
self.ismongos
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
