Question: Can you fix the below code meant for Jupyter Notebook: Traceback ( most recent call last ) Input In [ 6 ] , in animal

Can you fix the below code meant for Jupyter Notebook: Traceback (most recent call last)
Input In [6], in
animal_shelter.py
from pymongo import MongoClient
from bson.objectid import ObjectId
class AnimalShelter(object):
"""CRUD operations for Animal collection in MongoDB"""
def __init__(self, username, password):
# Initializing the MongoClient
USER = 'aacuser'
PASS = 'Justice01!'
HOST ='nv-desktop-services.apporto.com'
PORT =30918
DB = 'AAC'
COL = 'animals'
# The below Code Initialized the Connection
self.client = MongoClient('mongodb://%s:%s@%s:%d'%(USER,PASS,HOST,PORT))
self.database = self.client['%s'%(DB)]
self.collection = self.database['%s'%(COL)]
def create(self, data):
if data is not None:
self.database.animals.insert_one(data)
return True
else:
raise Exception("Nothing to save, because data parameter is empty")
return False
#Method to implement the R in CRUD:
def read_all(self, data):
cursor = self.database.animals.find(data,{'_id': False})
return cursor
def read(self, data):
return self.database.animals.find_one(data)
Python_Testing_Script.ipynb
from animal_shelter import AnimalShelter
shelter = AnimalShelter("aacuser", "Justice01!")
# Test create method
data ={"Age": "2 years", "Type": "Dog"}
if shelter.create(data):
print("Animal has been added.")
else:
raise Exception("Error: Animal not added, please try again.")
# Test read method
animals = shelter.read({"Type": "Dog"})
print(animals)
Can you fix the below code 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!