Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django TypeError:应为字符串参数,获取“bytes”python 3_Django_Amazon S3_Python 3.4_Django Storage - Fatal编程技术网

Django TypeError:应为字符串参数,获取“bytes”python 3

Django TypeError:应为字符串参数,获取“bytes”python 3,django,amazon-s3,python-3.4,django-storage,Django,Amazon S3,Python 3.4,Django Storage,我有一个django应用程序,它在1.6上运行,带有Python3。最近,我将django存储添加到我的应用程序中 当我试图保存一个以前运行良好的modelrecord时,它会显示以下错误 Traceback (most recent call last): File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_re

我有一个django应用程序,它在1.6上运行,带有Python3。最近,我将django存储添加到我的应用程序中

当我试图保存一个以前运行良好的modelrecord时,它会显示以下错误

Traceback (most recent call last):
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 432, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 198, in inner
    return view(request, *args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 29, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 25, in bound_func
    return func(self, *args2, **kwargs2)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/transaction.py", line 371, in inner
    return func(*args, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1131, in add_view
    self.save_model(request, new_object, form, False)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 860, in save_model
    obj.save()
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 545, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 573, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 654, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 687, in _do_insert
    using=using, raw=raw)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/manager.py", line 232, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/query.py", line 1514, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 902, in execute_sql
    for sql, params in self.as_sql():
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 860, in as_sql
    for obj in self.query.objs
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 860, in <listcomp>
    for obj in self.query.objs
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 858, in <listcomp>
    for f in fields
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 252, in pre_save
    file.save(file.name, file, save=False)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 87, in save
    setattr(self.instance, self.field.name, self.name)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 311, in __set__
    self.field.update_dimension_fields(instance, force=True)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 381, in update_dimension_fields
    width = file.width
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/images.py", line 17, in _get_width
    return self._get_image_dimensions()[0]
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/images.py", line 27, in _get_image_dimensions
    self.open()
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 76, in open
    self.file.open(mode)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/base.py", line 121, in open
    if not self.closed:
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/base.py", line 59, in _get_closed
    return not self.file or self.file.closed
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 406, in _get_file
    self.key.get_contents_to_file(self._file)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1643, in get_contents_to_file
    response_headers=response_headers)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1475, in get_file
    query_args=None)
  File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1529, in _get_file_internal
    fp.write(bytes)


TypeError: string argument expected, got 'bytes'
当我试图从管理模型和视图保存RequisitionImage对象记录时,我遇到了这个错误


那么如何避免这个错误以及是什么导致了它呢?

我认为django存储不支持python3。请看@lalo:是的,lalo,我使用的是基于这个原因而得到python3支持的@RakeshVidyaChandra,你有没有想过这个问题?我对boto s3也有同样的问题,错误类型为error:string参数应为,从文件/venv/csp3/lib/python3.4/site-packages/boto/s3/key.py中获取“bytes”,第1536行,在_get_File_internal fp.writebytes中可以在python 2.7中正常工作。
class RequisitionImage(models.Model, ImageRisizeToolbox):
    image_id = models.AutoField(primary_key=True)
    requisition = models.ForeignKey(Requisition)
    description = models.CharField(max_length=80)
    image_file = models.ImageField(upload_to=get_file_path, height_field='image_height', width_field='image_width')
    thumbnail_file = models.ImageField(upload_to=get_file_path, blank=True, null=True)
    sort_order = models.SmallIntegerField(blank=True, null=True)
    filetype = models.CharField(max_length=10, blank=True, null=True)
    objects = models.Manager()
    cust_objects = RequisitionImageManager()

    MAX_SIZE = 4000000 # Image file size limit

    def __str__(self):
        return self.description