2016-06-29 25 views
0

Die Python-Version ist 2.8.2 und wird in Eclipse verwendet. Ich erhalte diese Störung, wenn ich versuche, den folgenden Befehl auszuführen:TypeError: file() Argument 1 muss eine codierte Zeichenfolge ohne NULL Bytes sein, nicht str odoo

Die Funktion ist:

@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) 

Der Fehler, der ausgelöst wird ist:

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 

Bitte helfen Sie mir mit diesem Thema .

Die anderen Referenzen sagen über die URL der Datei. Dies ist ein anderes Szenario.

Antwort

0

Sie versuchen, den dekodierten base64-Inhalt der Datei zu öffnen, Sie sollen die Datei selbst öffnen.

PIL.Image.open(self.image) 

nehmen dies zum Beispiel, den Fehler zu reproduzieren, Sie bekommen

>>> 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 
>>> 

der Charakter '\0' als NullByte gesehen, die das decodierte Bild enthält

+0

Also, was soll ich tun, um zu öffnen es?? –

+0

ist schon in der Antwort. 'PIL.Image.open (Selbstbild)' – danidee

Verwandte Themen