Diagram
AttributeError: ‘dict’ object has no attribute ‘iteritems’ error occurs when you try to “access the iteritems() method on a dictionary, but it was deprecated in Python 3.7 and removed in Python 3.10.”
To fix the AttributeError: ‘dict’ object has no attribute ‘iteritems’ error, use the “items()” method instead of the “iteritems()” method.
Reproduce the error
main_dict = {
'key1': 'value1',
'key2': 'value2'
}
for key, value in main_dict.iteritems():
print(key, value)
Output
Here are the ways to fix the error:
For Python 3, use the “items()” method
main_dict = {
'key1': 'value1',
'key2': 'value2'
}
for key, value in main_dict.items():
print(key, value)
Output
key1 value1
key2 value2
For Python 2, use the “iteritems()” method
main_dict = {
'key1': 'value1',
'key2': 'value2'
}
for key, value in main_dict.iteritems():
print(key, value)
Output
key1 value1
key2 value2
The iteritems() method was a legacy used in older Python versions. Using the iteritems() method is no longer necessary, as the items() method can be used instead.
Replacing iteritems() with items() can fix the error and make your code compatible with Python 3.
That’s it!
Related posts
AttributeError: ‘dict’ object has no attribute ‘id’
AttributeError: ‘dict’ object has no attribute ‘replace’
AttributeError: ‘dict’ object has no attribute ‘headers’
AttributeError: ‘dict’ object has no attribute ‘encode’
AttributeError: ‘dict’ object has no attribute ‘add’
AttributeError: ‘dict’ object has no attribute ‘has_key’
AttributeError: ‘dict’ object has no attribute ‘read’

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.