我正在使用以下脚本读取csv文件并对其进行解码。运行它时,我收到不正确的填充错误。当我输入单个条目并执行str.decode('base64')
时,会得到适当的结果(没有错误)。可能是什么问题呢?某些条目可能会被破坏,从而使整个过程中断吗?
def get_sigpair_from_csv(csv_in, start=0, skip_to_tx=None, want_tx=[]):
want_tx=set(want_tx)
skip_entries = True
with open(csv_in,'r') as f:
for nr,line in enumerate(f):
if nr<start:
if nr%100000==0:
print "skip",nr,f.tell()
continue
if nr % 10000000 == 0:
print "10m", nr
try:
# read data
cols = line.split(";",1)
tx = cols[0].strip()
if skip_to_tx and tx==skip_to_tx:
skip_entries=False
# skip this entry - already in db
continue
if skip_to_tx and skip_entries:
print "skiptx",nr, tx
continue
if want_tx and tx not in want_tx:
continue
scriptsig = cols[1].decode("base64")
sig = scriptsig_to_ecdsa_sig(scriptsig)
sig['tx'] = tx
sig['nr'] = nr
yield sig
except ValueError, ve:
#print tx,repr(ve)
pass
except Exception, e:
print tx, repr(e)
以下是输出示例:
879b068c75492e9d860763e843212d7aed2fb81ad3ee24592b48cdf5df624dcd Error('Incorrect padding',)
但是,当我这样做时:
x = '879b068c75492e9d860763e843212d7aed2fb81ad3ee24592b48cdf5df624dcd'
x.decode('base64')
有效