I am trying to use requests.get()
to open/get a file for image processing but my code falls over when I try to do an Image.open()
with the file I have just got.
My code is:
conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
bucket = conn.get_bucket(settings.AWS_STORAGE_BUCKET_NAME)
for key in bucket.list(prefix='media/userphotos'):
file_name=key.name
full_path_filename = 'https://' + settings.AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/' + file_name
fd_img = requests.get(full_path_filename);
img = Image.open(fd_img)
img = resizeimage.resize_width(img, 800)
new_filename = file_name
new_filename.replace('userphotos', 'webversion')
full_path_filename = 'https://' + settings.AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/' + new_filename
img.save(full_path_filename, img.format)
fd_img.close()
The traceback is:
Traceback:
File "/Users/billnoble/Documents/YHistory-Server/yhistoryvenv/lib/python3.4/site-packages/PIL/Image.py" in open
2275. fp.seek(0)
During handling of the above exception ('Response' object has no attribute 'seek'), another exception occurred:
File "/Users/billnoble/Documents/YHistory-Server/yhistoryvenv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/Users/billnoble/Documents/YHistory-Server/yhistoryvenv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/billnoble/Documents/YHistory-Server/items/views.py" in xformpics
67. img = Image.open(fd_img)
File "/Users/billnoble/Documents/YHistory-Server/yhistoryvenv/lib/python3.4/site-packages/PIL/Image.py" in open
2277. fp = io.BytesIO(fp.read())
Exception Type: AttributeError at /xformpics
Exception Value: 'Response' object has no attribute 'read'
It all works fine up to the Image.open()
.
I have spent many hours googling this issue but cannot find a solution.