我把OdooV11的python2升级到python3。之后我编辑了我的插件。我的一个插件,我搞错了。
result = method(recs, *args, **kwargs)
File "D:\Odoo 11.0\server\addons\addons-
trbase\l10n_tr_account_einvoice\models\account_einvoice_provider.py",
line 698, in action_einvoice_get_invoices
self.einvoice_get_invoices()
File "D:\Odoo 11.0\server\addons\addons- unauth\l10n_tr_account_einvoice_provider_isis\models\account_einvoice_provider.py", line 272, in einvoice_get_invoices
bytedata = base64.decodestring(result.ByteData)
File "D:\Odoo 11.0\python\lib\base64.py", line 552, in decodebytes
_input_type_check(s)
File "D:\Odoo 11.0\python\lib\base64.py", line 520, in _input_type_check
raise TypeError(msg) from err
TypeError: expected bytes-like object, not Text
巨蟒这么说;
decodebytes()的别名已弃用。
自3.1版起已弃用。
我正在尝试decodebytes()而不是decodestring(),但它不起作用。
以下是我的课堂方法:
def einvoice_get_invoices(self):
if self.provider != 'isis':
return super(AccountEinvoiceProvider, self).einvoice_get_invoices()
else:
try:
client = self.isis_get_client()
count = 0
while count < 50:
count += 1
result = client.service.GetSingleEnvelope(self.company_id.vat[2:])
self.isis_check_error(result)
if result.EnvelopeUUID:
bytedata = base64.decodestring(result.ByteData)
buffer = io.BytesIO(bytedata)
if zipfile.is_zipfile(buffer):
file = zipfile.ZipFile(buffer, 'r')
for name in file.namelist():
bytedata = file.read(name)
_logger.debug("Processing Envelope: %s" % bytedata.decode('utf-8'))
self.einvoice_process_envelope(bytedata)
else:
_logger.info("Invalid Zip File! EnvelopeUUID= %s" % result.EnvelopeUUID)
else:
count = 50
return True
except WebFault as e:
_logger.error(_('E-Invoice Provider WebService Error!') + '\n\n' + e.message)
return False
我怎样才能修好它?
最佳答案
我解决了一个类似的问题,不完全是你的。
就我而言,错误是:
TypeError: expected bytes-like object, not 'str'
解决方案是在使用(unicode)字符串之前对其进行编码:
bytedata = base64.decodestring(result.ByteData.encode())
我根本不知道什么样的变量是
result.ByteData
,所以我不确定encode()
方法是否适用于这里。