报错:TypeError: decoding to str: need a bytes-like object, int found


解决方案:

               

def replace_new(s):
# 读取出来的数据用context的数据去替换,loan_id 动态替换
p = '\$\{(.*?)}'
while re.search(p, s):
m = re.search(p, s)
key = m.group(1)
if hasattr(Context, key):
value = str(getattr(Context, key)) #重点: 取出来的是int类型,所以应该转换成字符串去替换
s = re.sub(p, value, s, count=1)
else:
return None
return s
s = '{"mobilephone": "${borrow_user}", "pwd": "${borrow_pwd}"}'
s = replace_new(s)
print(s)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM