Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In [23]: user.primary_image = image_url
- In [24]: user.save()
- In [25]: r = requests.get(image_url)
- In [26]: img_temp = NamedTemporaryFile(delete=True)
- In [27]: img_temp.write(r.content)
- Out[27]: 8204
- In [28]: img_temp.flush()
- In [29]: user.primary_image.save("image.jpg", File(img_temp), save=True)
- > /home/jim/Desktop/pyco/test/app/user/models/user.py(25)upload_image_to()
- -> mime_type = imghdr.what(instance.primary_image)
- (Pdb) c
- ---------------------------------------------------------------------------
- ClientError Traceback (most recent call last)
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/storages/backends/s3boto3.py in _open(self, name, mode)
- 409 try:
- --> 410 f = S3Boto3StorageFile(name, mode, self)
- 411 except ClientError as err:
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/storages/backends/s3boto3.py in __init__(self, name, mode, storage, buffer_size)
- 68 # Force early RAII-style exception if object does not exist
- ---> 69 self.obj.load()
- 70 self._is_dirty = False
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/boto3/resources/factory.py in do_action(self, *args, **kwargs)
- 504 def do_action(self, *args, **kwargs):
- --> 505 response = action(self, *args, **kwargs)
- 506 self.meta.data = response
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/boto3/resources/action.py in __call__(self, parent, *args, **kwargs)
- 82
- ---> 83 response = getattr(parent.meta.client, operation_name)(**params)
- 84
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
- 319 # The "self" in this scope is referring to the BaseClient.
- --> 320 return self._make_api_call(operation_name, kwargs)
- 321
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
- 623 error_class = self.exceptions.from_code(error_code)
- --> 624 raise error_class(parsed_response, operation_name)
- 625 else:
- ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
- During handling of the above exception, another exception occurred:
- OSError Traceback (most recent call last)
- <ipython-input-29-bed9a9f3e7b2> in <module>()
- ----> 1 user.primary_image.save("image.jpg", File(img_temp), save=True)
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/django/db/models/fields/files.py in save(self, name, content, save)
- 84
- 85 def save(self, name, content, save=True):
- ---> 86 name = self.field.generate_filename(self.instance, name)
- 87 self.name = self.storage.save(name, content, max_length=self.field.max_length)
- 88 setattr(self.instance, self.field.name, self.name)
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/django/db/models/fields/files.py in generate_filename(self, instance, filename)
- 300 """
- 301 if callable(self.upload_to):
- --> 302 filename = self.upload_to(instance, filename)
- 303 else:
- 304 dirname = datetime.datetime.now().strftime(self.upload_to)
- ~/Desktop/pyco/test/app/user/models/user.py in upload_image_to(instance, filename)
- 23 def upload_image_to(instance, filename):
- 24 import pdb; pdb.set_trace()
- ---> 25 mime_type = imghdr.what(instance.primary_image)
- 26 # Normalize jpeg to jpg
- 27 if mime_type == 'jpeg':
- /usr/lib/python3.6/imghdr.py in what(file, h)
- 17 h = f.read(32)
- 18 else:
- ---> 19 location = file.tell()
- 20 h = file.read(32)
- 21 file.seek(location)
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/django/core/files/utils.py in <lambda>(self)
- 19 readlines = property(lambda self: self.file.readlines)
- 20 seek = property(lambda self: self.file.seek)
- ---> 21 tell = property(lambda self: self.file.tell)
- 22 truncate = property(lambda self: self.file.truncate)
- 23 write = property(lambda self: self.file.write)
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/django/db/models/fields/files.py in _get_file(self)
- 41 self._require_file()
- 42 if not hasattr(self, '_file') or self._file is None:
- ---> 43 self._file = self.storage.open(self.name, 'rb')
- 44 return self._file
- 45
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/django/core/files/storage.py in open(self, name, mode)
- 31 def open(self, name, mode='rb'):
- 32 """Retrieve the specified file from storage."""
- ---> 33 return self._open(name, mode)
- 34
- 35 def save(self, name, content, max_length=None):
- ~/Desktop/pyco/test/env/lib/python3.6/site-packages/storages/backends/s3boto3.py in _open(self, name, mode)
- 411 except ClientError as err:
- 412 if err.response['ResponseMetadata']['HTTPStatusCode'] == 404:
- --> 413 raise IOError('File does not exist: %s' % name)
- 414 raise # Let it bubble up if it was some other error
- 415 return f
- OSError: File does not exist: https:/picsum.photos/id/122/200/300
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement