attributeerror: ‘str’ object has no attribute ‘read’ [SOLVED]
In this tutorial, we will provide solutions for attributeerror: ‘str’ object has no attribute ‘read’ error. Apart from it, we will discover the causes and have a brief discussion of …
itsourcecode.com hosts 170+ documented fixes for Python AttributeError messages: the most common runtime error after TypeError. From beginner-level confusion ('NoneType' object has no attribute 'split') to library-version pain (module 'numpy' has no attribute 'float' after NumPy 1.20+), this archive groups every documented error by root cause. Each post explains why the attribute is missing and gives 2-4 alternative fixes with code examples.
What is an AttributeError?
A Python AttributeError is raised when you try to access an attribute or method on an object that doesn’t have it. The error message always tells you both the object type and the missing attribute, for example AttributeError: 'list' object has no attribute 'items' means you called .items() on a list, but only dicts have that method. The error has two forms:
Instance form: 'X' object has no attribute 'Y', the value at runtime isn’t the type you expected
Module form: module 'X' has no attribute 'Y', the function/class you’re importing no longer exists in that version of the library
How to debug any AttributeError in 4 steps
Read both names in the error. The message gives you the object type AND the missing attribute. Note both, they tell you what’s wrong together.
Print the type of the object. Add print(type(x)) on the line before the error. If the error says 'NoneType' object has no attribute 'split', the value is actually None, usually because a function returned nothing when you expected a string.
If the error is “module X has no attribute Y”, check the library version. Run pip show to see installed version. Compare to the version that had the attribute, often the API was deprecated and renamed. Common offenders: NumPy (np.float, np.int, np.long removed in 1.20+), pandas (.ix removed in 1.0+), Keras (keras.optimizers.Adam moved), Selenium (find_element_by_id removed in 4.0+).
Check the import path. from numpy import float and numpy.float are different namespaces and different lookups. Many AttributeErrors come from a sub-package that moved or was renamed across versions.
Most common root causes (in order of frequency)
Value is None when you expected an object: function returned None, regex match failed, dict lookup returned None, BeautifulSoup didn’t find the element
Library version mismatch: API was deprecated and removed (numpy 1.20+, pandas 1.0+, Keras 2.x → tf.keras, Selenium 4)
Wrong type altogether: calling .items() on a list, .append() on a string, .read() on a dict
Python 2 → 3 migration: old code using dict.iteritems(), dict.has_key(), urllib.urlopen
Module re-org: imports from tensorflow.contrib (removed), keras.optimizers.Adam (moved to tf.keras.optimizers)
Typo in attribute name: beginners hit this most, especially when an IDE doesn’t autocomplete
Featured AttributeError fixes by type
🟢 Python built-in types: NoneType, str, list, dict, set, tuple
These errors come from runtime type confusion, your code expects one type but got another. Almost always fixable with a one-line type check or rewriting the previous line that returned the wrong value.
NoneType errors (14 posts): the most common AttributeError class. A function/method returned None when you expected a string, list, or object.
‘NoneType’ object has no attribute ‘split’
‘NoneType’ object has no attribute ‘strip’
‘NoneType’ object has no attribute ‘find’ (BeautifulSoup)
‘NoneType’ object has no attribute ‘text’
‘NoneType’ object has no attribute ‘cursor’ (database)
str errors (10 posts): calling list/dict methods on a string.
‘str’ object has no attribute ‘keys’
‘str’ object has no attribute ‘get’
‘str’ object has no attribute ‘append’
‘str’ object has no attribute ‘remove’
‘str’ object has no attribute ‘write’
‘str’ object has no attribute ‘decode’ (Python 3 migration)
list errors (10 posts): calling string/dict methods on a list.
‘list’ object has no attribute ‘items’
‘list’ object has no attribute ‘strip’, 2026 Guide
‘list’ object has no attribute ‘shape’, 2026 Guide
‘list’ object has no attribute ‘join’
dict errors (6 posts): Python 2 methods removed in Python 3.
‘dict’ object has no attribute ‘iteritems’ (Py3 migration)
‘dict’ object has no attribute ‘has_key’ (Py3 migration)
‘dict’ object has no attribute ‘add’, 2026 Guide
‘dict’ object has no attribute ‘read’
set, float, bytes errors
‘set’ object has no attribute ‘items’
‘float’ object has no attribute ‘split’
🐼 pandas (DataFrame, Series): 13 posts
pandas had multiple API breaks between 0.x → 1.x → 2.x. Old code using .ix, .append(), or older indexing methods raises AttributeError on modern pandas.
‘DataFrame’ object has no attribute ‘ix’ (use .loc / .iloc)
‘DataFrame’ object has no attribute ‘unique’
‘DataFrame’ object has no attribute ‘concat’
‘DataFrame’ object has no attribute ‘write’
‘DataFrame’ object has no attribute ‘_get_object_id’
‘DataFrame’ object has no attribute ‘withColumn’ (PySpark vs pandas)
‘Series’ object has no attribute ‘strftime’
‘Series’ object has no attribute ‘split’
Pandas .dt accessor with datetimelike values
module ‘pandas’ has no attribute ‘read_csv’
🔢 NumPy (module + ndarray): 16 posts
NumPy 1.20 deprecated and removed many type aliases (np.float, np.int, np.long, np.bool). Code from 2019 or earlier hits these errors immediately on modern NumPy.
module ‘numpy’ has no attribute ‘object’
module ‘numpy’ has no attribute ‘float’
module ‘numpy’ has no attribute ‘long’
module ‘numpy’ has no attribute ‘ndarray’, 2026 Guide
🤖 TensorFlow & Keras: 15 posts
TensorFlow 2.x reorganized the API: tensorflow.contrib was removed, optimizers moved into tf.keras.optimizers, and many sub-modules were merged or deprecated.
module ‘tensorflow.compat.v1’ has no attribute ‘contrib’
module ‘tensorflow’ has no attribute ‘set_random_seed’
module ‘keras.utils’ has no attribute ‘Sequence’
module ‘keras.optimizers’ has no attribute ‘Adam’
‘Tensor’ object has no attribute ‘numpy’
🔥 PyTorch & TorchText: 3 posts
module ‘torchtext.data’ has no attribute ‘Field’ (torchtext 0.9+)
module ‘torch._C’ has no attribute ‘_cuda_setDevice’
📈 Matplotlib (module-level): 2 posts
module ‘matplotlib’ has no attribute ‘plot’ (use pyplot)
module ‘matplotlib’ has no attribute ‘get_data_path’
‘AxesSubplot’ object has no attribute ‘savefig’
👁️ OpenCV (cv2): 2 posts
module ‘cv2’ has no attribute ‘xfeatures2d’ (need opencv-contrib)
module ‘cv2’ has no attribute ‘_registerMatType’
🕷️ Selenium WebDriver: 3 posts
Selenium 4 removed the find_element_by_* methods. Use find_element(By.X, ...) instead.
‘WebDriver’ object has no attribute ‘find_element_by_class_name’
module ‘selenium.webdriver’ has no attribute ‘PhantomJS’ (deprecated)
module ‘selenium.webdriver’ has no attribute ‘Opera’
⚙️ Standard library & misc modules
module ‘datetime’ has no attribute ‘now’
module ‘asyncio’ has no attribute ‘run’ (Python 3.7+)
module ‘collections’ has no attribute ‘Iterable’ (Py3.10+ moved to collections.abc)
module ‘urllib’ has no attribute ‘urlopen’ (Py3: use urllib.request)
AttributeError: __enter__ (context manager protocol)
module ‘h11’ has no attribute ‘Event’
‘entrypoints’ object has no attribute ‘get’
‘API’ object has no attribute ‘search’ (Tweepy)
2026 Updated Guides: featured AttributeError fixes
These guides were rewritten or expanded in 2026 with current library versions, minimal reproductions, and 3-4 alternative fixes each.
module ‘numpy’ has no attribute ‘ndarray’: NumPy 1.20+ migration
‘list’ object has no attribute ‘strip’: String method confusion
‘list’ object has no attribute ‘shape’: NumPy vs list confusion
‘dict’ object has no attribute ‘add’: set vs dict confusion
module ‘pandas’ has no attribute ‘read_csv’: shadowed import
‘DataFrame’ object has no attribute ‘ix’: pandas 1.0+ migration (use .loc / .iloc)
Pandas .dt accessor error: datetime column conversion
‘Tensor’ object has no attribute ‘numpy’: TensorFlow eager execution
‘WebDriver’ has no attribute ‘find_element_by_class_name’: Selenium 4 migration
module ‘asyncio’ has no attribute ‘run’: Python 3.7+ async
‘tensorflow.compat.v1’ has no attribute ‘contrib’: TF 2.x migration
‘set’ object has no attribute ‘items’: set vs dict
‘list’ object has no attribute ‘items’: list of dicts vs dict
AttributeError: __enter__: using with on non-context-manager
Related error categories
AttributeError is one of 10 hubs in our Python & JavaScript error reference cluster, 980+ documented fixes total. If your error isn’t about a missing attribute, jump to the right hub below:
TypeError Reference, 220+ Python & JS TypeError fixes
ModuleNotFoundError Reference, 198+ Python import errors
ValueError Reference, 100+ library-specific Python ValueError fixes
ImportError Reference, 67+ “cannot import name X from Y” fixes
NameError Reference, 49+ Python “name X is not defined” fixes
RuntimeError Reference, 49+ PyTorch CUDA, asyncio, Flask runtime errors
SyntaxError Reference, 48+ Python & JavaScript parsing errors
ReferenceError Reference, 34+ JavaScript “is not defined” fixes
HTTP Error Reference, 35+ HTTP status code fixes
Python Tutorial, beginner-to-intermediate Python lessons
About this AttributeError reference
This AttributeError reference has been built since 2015 by PIES Information Technology Solutions in Binalbagan, Negros Occidental, Philippines. Every post in the collection started as a real error encountered in production code, by us, by our clients, or by readers who emailed us with their tracebacks. Used by 12,000+ Python developers monthly across the Philippines, India, the United States, and beyond. If your AttributeError isn’t here, send the full traceback to our contact form and we’ll add it.
In this tutorial, we will provide solutions for attributeerror: ‘str’ object has no attribute ‘read’ error. Apart from it, we will discover the causes and have a brief discussion of …
The attributeerror: module ‘numpy’ has no attribute ‘int’ appears while you are using the NumPy library in your Python script. In this article, we show you the different solutions to …
Are you looking for a solution to the Python error attributeerror: module torchtext.data has no attribute field? To find a solution and completely comprehend this error, read this article through …
Encountering the attributeerror: module ‘numpy’ has no attribute ‘asscalar’ in Python? You’re on the right site, as in this article, we will show you how to solve this error. The …
In this tutorial, we will explore solutions for fixing attributeerror module scipy.sparse has no attribute coo_array error. Together with a brief discussion, and example codes for a better understanding of …
The attributeerror: module ‘cgi’ has no attribute ‘escape’ is an error message in Python. It is a common error that a developer encounters while working with CGI scripts in Python. …
In this tutorial, we will discuss the best way to resolve the attributeerror: module torch._c has no attribute cuda_setdevice. What is _cuda_setdevice? The _cuda_setdevice is a function in the PyTorch …
Are you encountering the attributeerror numpy ndarray object has no attribute iloc? Well in this article we will look for the solutions, along with example codes and a brief discussion …
In this article, you will discover the solution for attributeerror: module ‘cv2’ has no attribute ‘registermattype’ error message that you encounter while working with OpenCV in Python. This error can …
Looking for a quick fix to the attributeerror: module ‘backend_interagg’ has no attribute ‘figurecanvas’ in Python? Read until the end of this article, and your problem will surely be fixed. …
In this tutorial, we will discuss the solutions on how to resolved the attributeerror: module ‘logging’ has no attribute ‘config’. What is logging in python? Logging is an inbuilt module …
Are you familiar with the attributeerror: module ‘keras.preprocessing.image’ has no attribute ‘load_img’? Have you ever come across one like this? Why does this error occur? We know how frustrating it …
Are encountering attributeerror: module ‘numpy.random’ has no attribute ‘bitgenerator’? Well, in this article we will look for solutions on how to fix the error as well as examples to provide …