【问题标题】:How to handle TypeError after switching to Python3切换到 Python3 后如何处理 TypeError
【发布时间】:2019-07-04 15:09:50
【问题描述】:

最近,我们将代码从 python 2.7 迁移到了 Python3.6。在此之后,Test rail apis 无法正常工作。我尝试转换为 Unicode,b'get_projectxx',但似乎没有任何效果。

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

在这里,我将 self.project_id 传递为 20

我总是遇到错误:

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

知道如何解决这个问题吗?任何帮助表示赞赏。谢谢!

【问题讨论】:

    标签: python python-3.x testrail


    【解决方案1】:

    听起来send_get 是引发错误的方法(它期望可以按原样发送的一系列字节,而不是必须编码的字符串)。使用 bytes 文字而不是 str 文字:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      相关资源
      最近更新 更多