title: Getting an Image from URL in Python: cannot identify image file <_io.BytesIO object at 0x7f890a076db0>
body: <p>I have a list of thousands of urls that I need to use to grab images.</p>
  
  <p>The urls are stored in a list, and iterate over each url running the below code. The example is shown for a specific url:</p>
  
  <pre><code>from PIL import Image, ImageFile
  import requests
  from io import BytesIO
  import urllib
  
  ImageFile.LOAD_TRUNCATED_IMAGES = True
  
  URL = 'https://www.sedie.ws/dynamic/common/data/d/files/45000/45217_2_3-med.jpg'
  
  label = 'table'
  
  r = requests.get(url = URL)
  
  filepath = "{}.jpeg".format(label)
  
  try:
      response = requests.get(URL)
      data = response.raw.read()
      data = BytesIO(data)
      im = Image.open(BytesIO(response.content))      
      im.thumbnail((64, 64))
      im.save(filepath) 
      count += 1
  
  except IOError as e:
      print(e, URL, '\n')
  </code></pre>
  
  <p>However this returns an error:</p>
  
  <pre><code>cannot identify image file &lt;_io.BytesIO object at 0x7f890a076db0&gt; https://www.sedie.ws/dynamic/common/data/d/files/45000/45217_2_3-med.jpg 
  </code></pre>
  
  <p>Could someone please explain how to handle this image correctly? I would like to simply skip this file and not have to download it, but I find that my try catch is still saving some files to my local system. However, upon trying to read them I get the above errors too.</p>