Python FTP grabbing and saving images issue

Posted by PylonsN00b on Stack Overflow See other posts from Stack Overflow or by PylonsN00b
Published on 2010-05-26T18:14:55Z Indexed on 2010/05/26 18:21 UTC
Read the original article Hit count: 234

Filed under:
|
|

OK So I have been messing with this all day long. I am fairly new to Python FTP. So I have searched through here and came up w/ this:

images = notions_ftp.nlst()
    for image_name in image_names:
        if found_url == False:
            try:
                for image in images:
                    ftp_image_name = "./%s" % image_name
                    if ftp_image_name == image:
                        found_url = True
                        image_name_we_want = image_name
            except:
                pass

    # We failed to find an image for this product, it will have to be done manually
    if found_url == False:
        log.info("Image ain't there baby -- SKU: %s" % sku)
        return False
    # Hey we found something! Open the image....
    notions_ftp.retrlines("RETR %s" % image_name_we_want, open(image_name_we_want, "rb"))
    1/0

So I have narrowed the error down to the line before I divide by zero. Here is the error:

Traceback (most recent call last):
  File "<console>", line 6, in <module>
  File "<console>", line 39, in insert_image
IOError: [Errno 2] No such file or directory: '411483CC-IT,IM.jpg'

So if you follow the code you will see that the image IS in the directory because image_name_we_want is set if found in that directory listing on the first line of my code. And I KNOW it's there because I am looking at the FTP site myself and ...it's freakin there. So at some point during all of this I got the image to save locally, which is most desired, but I have long since forgot what I used to make it do that. Either way, why does it think that the image isn't there when it clearly finds it in the listing.

© Stack Overflow or respective owner

Related posts about python

Related posts about image