斯潘8
斯潘4
你好,下面的python代码在python 3中不起作用,我收到一条“unicode对象必须在哈希前编码”的错误消息。有什么建议吗?
导入系统,获取选项,哈希库,操作系统
从hashlib导入sha1
导入HMAC
导入基准64
导入时间
导入请求
导入子进程
导入JSON
导入FME
导入FmeObjects
导入日期时间
def calculate_签名(功能):
#从功能属性获取输入值
api_key=fme_macrovalues['api']
host=feature.getattribute('host')
method=feature.getattribute('method')
shared_secret=fme_macrovalues['sharedsecret']
timestamp=feature.getattribute('时间戳')
#timestamp=datetime.datetime.utcnow()。
url=feature.getattribute('url')
#设置访问键
#access_key=fme_macrovalues['accesskey']
访问“a0f66a0e-0cc9-7abe-24cc-f807e2829ab”
#从Calculate_签名复制的代码
sig_block=“\r\n \r\n \r\n \r\n \r\n \r\n”.格式(
方法.upper(),
主机,
url.lower(),
时间戳,
API_密钥,
访问键)
print(“\n \n--sig block--\n”+sig ou block+“”\n \n“)
解码后的_secret=base64.b64解码(共享的_secret)
hashed=hmac.new(解码后的密码,信号块,沙哈)
sig=hashed.digest().encode(“base64”).rstrip('\n')
#将sig值作为属性添加到feature中
feature.setattribute('sig',sig)
#feature.setattribute('timestamp',str(timestamp))。
您好!@强力克,
也许您会发现使用2to3(一个Python工具)来自动代码转换很有用:https://docs.python.org/2/library/2to3.html网站
否则,此文档也可能对您有所帮助:https://docs.python.org/3/howto/pyporting.html网站
?2019安全亚搏在线软件公司|合法的