Python3 执行 JS 遇到编码错误

在Python3中执行JS代码时遇到了编码错误,错误表明问题不在JS代码本身,而在文件编码。通过搜索模块并修改相关编码设置后,程序得以正常运行。

Python3 执行 JS 遇到编码错误

Python3使用import execjs执行 JS 代码,

遇到如下报错,测试用 JS 直接执行是没有问题的,也就是说 JS 代码没有问题,问题出在文件编码上

UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 14769: illegal multibyte sequence
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\execjs\_abstract_runtime_context.py", line 37, in call
    return self._call(name, *args)
  File "C:\Python39\lib\site-packages\execjs\_external_runtime.py", line 92, in _call
    return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
  File "C:\Python39\lib\site-packages\execjs\_external_runtime.py", line 78, in _eval
    return self.exec_(code)
  File "C:\Python39\lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
    return self._exec_(source)
  File "C:\Python39\lib\site-packages\execjs\_external_runtime.py", line 87, in _exec_
    output = self._exec_with_pipe(source)
  File "C:\Python39\lib\site-packages\execjs\_external_runtime.py", line 103, in _exec_with_pipe
    stdoutdata, stderrdata = p.communicate(input=input)
  File "f:\WorkSpace\PythonProject\sojson_decrypt\subprocess.py", line 1130, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "f:\WorkSpace\PythonProject\sojson_decrypt\subprocess.py", line 1525, in _communicate
    stdout = stdout[0]

跟进subprocess.py这个模块搜索encoding=关键字,修改值为'utf-8'后,程序可正常运行

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值