Error: " 'Dict' Object Has No Attribute 'Iteritems' "

Error: 'dict' object has no attribute 'iteritems'

As you are in python3 , use dict.items() instead of dict.iteritems()

iteritems() was removed in python3, so you can't use this method anymore.

Take a look at Python 3.0 Wiki Built-in Changes section, where it is stated:

Removed dict.iteritems(), dict.iterkeys(), and dict.itervalues().

Instead: use dict.items(), dict.keys(), and dict.values()
respectively.

AttributeError: 'MultiDict' object has no attribute 'iteritems' when moving from localhost to heroku

This was solved by creating a new class

from werkzeug.datastructures import ImmutableMultiDict

class Dict:
'''Wrapper klass because iteritems no longer available in Python3.7 dict'''

def __init__(self, mapping):
self.mapping = ImmutableMultiDict(mapping)

def iteritems(self):
return self.mapping.items()

def __getattr__(self, attr):
return getattr(self.mapping, attr)

def __iter__(self):
return dict.__iter__(self.mapping)

And then adding post = Dict(post) prior to my process event.

AttributeError: 'dict' object has no attribute

It looks like you need to set the load_instance Meta class attribute to True, according to marshmallow-sqlalchemy docs. As suggested by G. Anderson, you can try to print the update object's type for confirmation, but it seems you are getting a default dict as the deserialized data, instead of an instance of your Application model, which could be achieved by doing the above-mentioned trick. The code could be written like this:

class ApplicationSchema(SQLAlchemyAutoSchema):
class Meta:
model = Application
include_relationships = True
load_instance = True


Related Topics



Leave a reply



Submit