2017-05-03 2 views
0

Ich versuche, ein luigi.LocalTarget zum Lesen zu öffnen, das auf eine Zip-Datei zeigt (damit ich einen Hash berechnen kann). Leider, wenn ich versuche, es zu lesen, erhalte ich einen UnicodeDecodeError, was bedeutet, dass er nicht als Binärdatei geöffnet wird.Eröffnung luigi.LocalTarget im Binär-Lesemodus (Decodierungsfehler)

Ich kann dies tun (ohne luigi) und es funktioniert gut

file_path = luigi.LocalTarget('myfile.zip') 
with open(file_path, 'rb') as f: 
    data = f.read(1048576) 

Aber wenn ich dies tun

target = luigi.LocalTarget(file_path) 
with target.open('rb') as f: 
    data = f.read(1048576) 

Ich erhalte diese

--------------------------------------------------------------------------- 
UnicodeDecodeError      Traceback (most recent call last) 
<ipython-input-28-5240759ed677> in <module>() 
     1 target = luigi.LocalTarget(file_path) 
     2 with target.open('rb') as f: 
----> 3  data = f.read(1048576) 

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py in decode(self, input, final) 
    319   # decode input (taking the buffer into account) 
    320   data = self.buffer + input 
--> 321   (result, consumed) = self._buffer_decode(data, self.errors, final) 
    322   # keep undecoded input until the next call 
    323   self.buffer = data[consumed:] 

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 10: invalid continuation byte 

Ich bin mit Python 3.6 und luigi 2.6.1. Vielen Dank im Voraus für jede Hilfe

Antwort

Verwandte Themen