2016-06-29 15 views
0

pythonバージョンは2.8.2であり、Eclipseで使用しています。TypeError:file()引数1は、str odooではなく、NULLバイトのない符号化文字列でなければなりません。

機能は次のとおりです:私は、次のコマンドを実行しようとしています。このエラーを取得しています

@api.one 
@api.depends('image') 
def _compute_image_details(self): 
    if self.image: 
     image_content = self.image.decode('base64') 
     print type(self.image) 
     print type(image_content) 

     # File size 
     self.size = len(image_content) 

     # Camera make and model from EXIF tags 
     img = PIL.Image.open(image_content) 
     exif_tags = img._getexif() 

     # 0x010f is a numeric code for the "make" exif field 
     # You can find a list of fields here: exiv2.org/tags.html 
     self.camera_maker = exif_tags.get(0x010f) 

上げてエラーがある:

Traceback (most recent call last): 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 537, in _handle_exception 
    return super(JsonRequest, self)._handle_exception(exception) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 574, in dispatch 
    result = self._call_function(**self.params) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 310, in _call_function 
    return checked_call(self.db, *args, **kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/service/model.py", line 113, in wrapper 
    return f(dbname, *args, **kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 307, in checked_call 
    return self.endpoint(*a, **kw) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 803, in __call__ 
    return self.method(*args, **kw) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 403, in response_wrap 
    response = f(*args, **kw) 
    File "/home/next/WORKSPACE/odoo-8.0/addons/web/controllers/main.py", line 944, in call_kw 
    return self._call_kw(model, method, args, kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/addons/web/controllers/main.py", line 936, in _call_kw 
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 241, in wrapper 
    return old_api(self, *args, **kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 363, in old_api 
    result = method(recs, *args, **kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/models.py", line 5873, in onchange 
    newval = record[name] 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/models.py", line 5571, in __getitem__ 
    return self._fields[key].__get__(self, type(self)) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/fields.py", line 820, in __get__ 
    self.determine_draft_value(record) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/fields.py", line 928, in determine_draft_value 
    self._compute_value(record) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/fields.py", line 867, in _compute_value 
    self.compute(records) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 239, in wrapper 
    return new_api(self, *args, **kwargs) 
    File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 397, in new_api 
    result = [method(rec, *args, **kwargs) for rec in self] 
    File "/home/next/WORKSPACE/odoo-8.0/addons/transform_webservice_example/image_example.py", line 33, in _compute_image_details 
    img = PIL.Image.open(image_content) 
    File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1955, in open 
    fp = __builtin__.open(fp, "rb") 
TypeError: file() argument 1 must be encoded string without NULL bytes, not str 

この問題で私を助けてください。

その他の参考資料では、ファイルのURLについて述べています。これは異なるシナリオです。

答えて

0

あなたはファイルのbase64で解読された内容を開こうとしていますが、ファイル自体を開くことになっています。

PIL.Image.open(self.image) 

あなたは文字'\0'は、復号画像は、私が開くために何をすべきだから、

+0

が含まれていNullByteと見られている

>>> open('\0') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: file() argument 1 must be encoded string without NULL bytes, not str >>> 

を取得しているエラーを再現するために、例えばこれを取りますそれ?? –

+0

その回答がすでにあります。 'PIL.Image.open(self.image)' – danidee

関連する問題