如何在 Jython 中将整数编码为 Base64 以进行 Open Refine?

How can I encode an integer into Base64 in Jython for Open Refine?

我想使用 Base64 将一个整数编码成一个短字符串,return Open Refine (Google Refine) 的值。

我找到了示例,但它们总是给我一个错误。

import base64
foo = base64.b64encode('1')
return foo

作品 returning "MQ=="

但是我想对整数1进行编码,下面的代码报错

import base64
foo = base64.b64encode(bytes([1]))
return foo

我找到的例子在这里:How to encode integer in to base64 string in python 3

您可以在 \xx 形式的字符串中使用二进制数据,其中 xx 是字节的十六进制表示形式。

使用 Python2(包括 Jython2)尝试:

foo = base64.b64encode('')

对于 Python3:

foo = base64.b64encode(b'')

我的结果:AQ==