TypeError:write()参数必须是str,而不是字节,UTF-16

时间:2016-07-06 18:56:33

标签: python selenium selenium-webdriver typeerror

所以我正在使用Selenium和python运行测试用例,我想为这些测试生成HTML测试报告。我发现这个资源应该为我做,http://tungwaiyip.info/software/HTMLTestRunner.html如果有人感兴趣它似乎真的很好,但我一直收到这个错误。

File "facebook.py", line 21, in <module>
HTMLTestRunner.main()
File "C:\Users\kporika\AppData\Local\Programs\Python\Python35-32\lib\unittest\main.py", line 94, in __init__
self.runTests()
File "C:\Users\kporika\PycharmProjects\Partha\HTMLTestRunner.py", line 816, in runTests
unittest.TestProgram.runTests(self)
File "C:\Users\kporika\AppData\Local\Programs\Python\Python35-32\lib\unittest\main.py", line 255, in runTests
self.result = testRunner.run(self.test)
File "C:\Users\kporika\PycharmProjects\Partha\HTMLTestRunner.py", line 631, in run
self.generateReport(test, result)
File "C:\Users\kporika\PycharmProjects\Partha\HTMLTestRunner.py", line 688, in generateReport
self.stream.write(output.encode('UTF-16'))
TypeError: write() argument must be str, not bytes

测试报告生成器的代码在这里https://github.com/tungwaiyip/HTMLTestRunner/blob/master/HTMLTestRunner.py创建者的github页面。我该如何解决?

ps如果有帮助,我正在运行python版本3.5。

1 个答案:

答案 0 :(得分:4)

fullReshapedDT$month <- with(fullReshapedDT, ceiling(week/4)) 是一个python2模块。 Python3区分fullReshapedDT[,.(monthly_attendance = actual/target,by=.(person_id, month)] HTMLTestRunner对象,而python2有strbytes

如错误消息所示,第688行需要unicode,而不是str对象。在the documentation clarifies时,str会将bytes对象转换为str.encode个对象。您需要将第688行修改为str

,而不是bytes

请注意,由于python2 / 3不兼容,很可能会出现更多错误。