The solutions mentioned above might work, but it misses one point that I would like to highlight i.e. when we fetch or retrieve the image url to read, we might not always get the actual image content if we don't pass the headers while making the get request.
for example:
request without Headers
import requests
url = "https://www.roaringcreationsfilms.com/rcsfilms-media/chankya-quotes-in-hindi-32.jpg"
data = requests.get(url).content
if we check the data:
print(data)
b'<head><title>Not Acceptable!</title></head><body><h1>Not Acceptable!</h1><p>An
appropriate representation of the requested resource could not be found on this server.
This error was generated by Mod_Security.</p></body></html>'
you see, we don't actually get the content of the image.
request with Headers
import requests
url = "https://www.roaringcreationsfilms.com/rcsfilms-media/chankya-quotes-in-hindi-32.jpg"
headers = {"User-Agent": "PostmanRuntime/7.31.1"}
data = requests.get(url, headers=headers).content
and, if we now check the data:
print(data)
b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\t\x06\x06\........\xfb\x04El\xb3\xa8L\xbc\xa12\xc6<\xc4\x891\xf2L|\xf7\x9eV\x18\xc5\xd8\x8f\x02\xca\xdc\xb1c+-\x96\'\x86\xcb,l\xb12;\x16\xd4j\xfd/\xde\xbf\xff\xd9'
Now, we get the actual content of the image.
Things to note are that different urls might require different combinations of the headers (such as "User-Agent", "Accept", "Accept-Encoding", etc.) to successfully get the data and some even might not require any headers. But it's always a good practice to pass "User-Agent" as a minimum required header while making the request.