简体   繁体   English

切换到Python3后如何处理TypeError

[英]How to handle TypeError after switching to Python3

Recently, We migrated our code from python 2.7 to Python3.6. 最近,我们将代码从python 2.7迁移到了Python3.6。 After this Test rail apis are not working. 在此之后,测试导轨api无法正常工作。 I tried converting to Unicode, b'get_projectxx' but nothing seems working. 我尝试转换为Unicode,b'get_projectxx',但似乎没有任何效果。

 self.project_name = self.client.send_get('get_project/%s' % self.project_id)['name']

here, I am passing self.project_id as 20 在这里,我将self.project_id传递为20

I am getting below error all the time : 我一直都遇到错误:

Exception: a bytes-like object is required, not 'str' <class 'TypeError'>

Any idea how to fix this issue ? 任何想法如何解决此问题? Any help is appreciated. 任何帮助表示赞赏。 Thanks! 谢谢!

It sounds like send_get is the method raising the error (it expects a series of bytes it can send as-is, rather than a string which it would have to encode). 听起来send_get是引发错误的方法(它希望可以按原样发送一系列字节,而不是必须编码的字符串)。 Use a bytes literal instead of a str literal: 使用bytes文字而不是str文字:

 self.project_name = self.client.send_get(b'get_project/%s' % self.project_id)['name']
                                          ^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM