解决:TypeError: decoding to str: need a bytes-like object, int found

在写接口自动化的时候,遇到一个报错,如下图:
解决:TypeError: decoding to str: need a bytes-like object, int found_第1张图片

报错:TypeError: decoding to str: need a bytes-like object, int found
抛出的主要意思就是,它在解码到str,需要一个字节的对象,找到的却是int

其实就是类型不符导致的,打了断点看下,是我封装的替换方法导致,如下图:
解决:TypeError: decoding to str: need a bytes-like object, int found_第2张图片
断点执行到这里时,已经把错误抛出来了,原因是我封装的方法里面使用了正则的替换功能【 re.sub() 】,主要是这个替换功能它只针对【string类型】替换,而我的传参里面是【int类型】。


解决方法:
把入参强制转成了【str类型】,这样就运行成功,如下图:
解决:TypeError: decoding to str: need a bytes-like object, int found_第3张图片
以上就是我的遇坑的总结,可能会解决你的问题,也可能解决不了你的问题,但还是希望对您有所帮助,感谢阅读,欢迎来扰!

一直都在努力变好中,希望您也是,加油!

解决:TypeError: decoding to str: need a bytes-like object, int found_第4张图片

你可能感兴趣的:(python,python)