Frequently Asked Questions
What is the difference between AttributeError and TypeError?
AttributeError says "this object exists but does not have the attribute/method you tried to access." TypeError says "the value's type is wrong for this operation entirely." For example, None.split() raises AttributeError (NoneType has no .split); None + 5 raises TypeError (you cannot add NoneType to int). Both are runtime errors caused by Python's dynamic typing, but they fail at different points.
How do I fix "'NoneType' object has no attribute X"?
The variable is None when you expected it to be an object. Most common causes: (1) A function returned nothing (no return statement, or fell off the end of an if). (2) dict.get(key) when the key is not present (returns None by default). (3) BeautifulSoup's .find() returned None because the element does not exist. (4) A database query returned no rows. Fix by adding a None check: if x is not None: x.do_thing() — or fix the upstream code that is producing None.
Why does "module 'numpy' has no attribute 'float'" / 'int' / 'long' happen?
NumPy 1.20 (released January 2021) deprecated np.float, np.int, np.long, np.bool, and np.object. NumPy 1.24 (Dec 2022) removed them entirely. Replace them with: np.float64, np.int64, Python's built-in float/int/bool, or downgrade to NumPy < 1.20 if you cannot change the code.
Why does "DataFrame object has no attribute 'ix'" happen?
.ix was deprecated in pandas 0.20 and removed in 1.0 (January 2020). It was ambiguous because it accepted both labels and positions. Replace with .loc (label-based) or .iloc (integer position-based). For df.ix[5, 'col'], use df.loc[5, 'col'] if 5 is a row label, or df.iloc[5, df.columns.get_loc('col')] if 5 is a position.
Why does "object has no attribute 'iteritems' / 'has_key'" happen?
You are running Python 3 code that used Python 2 methods. In Python 3, dict.iteritems() became dict.items(), and dict.has_key(k) became k in dict. Run a Python 2 to 3 conversion with 2to3 tool, or manually update: for k, v in d.iteritems() becomes for k, v in d.items(); if d.has_key('x') becomes if 'x' in d.
Why does "WebDriver has no attribute find_element_by_class_name" happen?
Selenium 4 (October 2021) removed all the find_element_by_* methods. Replace driver.find_element_by_class_name('foo') with driver.find_element(By.CLASS_NAME, 'foo'). Do not forget from selenium.webdriver.common.by import By. The same applies to find_element_by_id, find_element_by_xpath, find_element_by_css_selector, etc.
Should I catch AttributeError with try/except?
Generally no — AttributeError usually indicates a real bug in your code (wrong type, wrong API). Catching it hides the bug. The legitimate exception is duck typing patterns where you genuinely want to handle "this might or might not have method X": try: x.close() except AttributeError: pass. But for normal code, fix the type mismatch instead of catching the error.
How often is this AttributeError reference updated?
New posts are added weekly as we encounter errors in real projects. Existing posts are revised every 6-12 months when major library versions ship (NumPy 2.x, pandas 2.x, Selenium 4 to 5, TensorFlow versions). This page was last refreshed in May 2026.