Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:write()参数必须是str,而不是bytes,UTF-16_Python_Selenium_Selenium Webdriver_Typeerror - Fatal编程技术网

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

Python TypeError:write()参数必须是str,而不是bytes,UTF-16,python,selenium,selenium-webdriver,typeerror,Python,Selenium,Selenium Webdriver,Typeerror,因此,我正在使用Selenium和python运行测试用例,我想为这些测试生成HTML测试报告。我发现这个资源应该为我做这件事,如果有人感兴趣,它看起来真的很好,但我不断得到这个错误 File "facebook.py", line 21, in <module> HTMLTestRunner.main() File "C:\Users\kporika\AppData\Local\Programs\Python\Python35-32\lib\unittest\main.py", l

因此,我正在使用Selenium和python运行测试用例,我想为这些测试生成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
文件“facebook.py”,第21行,在
HTMLTestRunner.main()
文件“C:\Users\kporika\AppData\Local\Programs\Python\Python35-32\lib\unittest\main.py”,第94行,在uu init中__
self.runTests()
运行测试中的文件“C:\Users\kporika\PycharmProjects\Partha\htmlestrunner.py”,第816行
unittest.TestProgram.runTests(self)
runTests中的文件“C:\Users\kporika\AppData\Local\Programs\Python 35-32\lib\unittest\main.py”,第255行
self.result=testRunner.run(self.test)
文件“C:\Users\kporika\PycharmProjects\Partha\htmlestrunner.py”,第631行,正在运行
自我生成报告(测试、结果)
generateReport中第688行的文件“C:\Users\kporika\PycharmProjects\Partha\htmlestrunner.py”
self.stream.write(输出.encode('UTF-16'))
TypeError:write()参数必须是str,而不是bytes
测试报告生成器的代码在创建者的github页面中。我该如何解决这个问题


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

HTMLTStrunner
是一个python模块。Python3区分
str
bytes
对象,而python2有
unicode
str

正如错误消息所说,第688行需要一个
str
,而不是
bytes
对象。作为,
str.encode
str
对象转换为
bytes
对象。您需要将第688行修改为
self.stream.write(output.encode('UTF-16'))
,而不是
self.stream.write(output)


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

您尝试了什么,结果如何?请阅读有关如何提问的帮助主题。您需要研究自己的问题,找到代码示例等,并编写自己的代码来解决问题。如果你做了所有这些,但仍然无法理解,那么回来编辑你的问题,并添加你所做研究的笔记,你尝试过的代码,以及结果是什么。。。任何错误消息等。