在使用exejs运行js代码的时候发生如下报错,但是在命令行去运行js文件正常:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:ProgramDataAnaconda3libthreading.py", line 932, in _bootstrap_inner
self.run()
File "C:ProgramDataAnaconda3libthreading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:ProgramDataAnaconda3libsubprocess.py", line 1370, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 17: illegal multibyte sequence
Traceback (most recent call last):
File "xxx.py", line 11, in
ret = execjs.eval(s)
File "C:ProgramDataAnaconda3libsite-packagesexecjs__init__.py", line 51, in eval
return get().eval(source, cwd)
File "C:ProgramDataAnaconda3libsite-packagesexecjs_abstract_runtime.py", line 25, in eval
return self.compile('', cwd=cwd).eval(source)
File "C:ProgramDataAnaconda3libsite-packagesexecjs_abstract_runtime_context.py", line 27, in eval
return self._eval(source)
File "C:ProgramDataAnaconda3libsite-packagesexecjs_external_runtime.py", line 78, in _eval
return self.exec_(code)
File "C:ProgramDataAnaconda3libsite-packagesexecjs_abstract_runtime_context.py", line 18, in exec_
return self._exec_(source)
File "C:ProgramDataAnaconda3libsite-packagesexecjs_external_runtime.py", line 87, in _exec_
output = self._exec_with_pipe(source)
File "C:ProgramDataAnaconda3libsite-packagesexecjs_external_runtime.py", line 103, in _exec_with_pipe
stdoutdata, stderrdata = p.communicate(input=input)
File "C:ProgramDataAnaconda3libsubprocess.py", line 1028, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:ProgramDataAnaconda3libsubprocess.py", line 1420, in _communicate
stdout = stdout[0]
IndexError: list index out of range
解决方式:
搜索界面通过管理员身份运行powershell
切换到解释器的路径下cd C:ProgramDataAnaconda3Lib
编辑subprocess.py文件notepad .subprocess.py
将subprocess.py中的class Popen类初始化的encoding=None修改为encoding='utf-8'
再次运行代码正常
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)