python执行js文件报错_Python运行execjs中出现编码问题

本文介绍了在使用Python的execjs执行JavaScript时遇到的编码错误,并提供了解决方案:在subprocess.py模块的Popen类构造方法中将encoding参数设为'utf-8'。这种修改有助于避免因文件编码不匹配导致的执行失败。
摘要由CSDN通过智能技术生成

使用python的execjs执行js,会有这个错误:

df0000013254

错误代码截图001

这个问题原因是文件编码问题,具体可以Google一下,这里直接解决方法是通过修改subprocess.py中的Popen类的构造方法__init__中encoding参数的默认值为utf-8。

代码修改前:

# 部分代码

_child_created = False # Set here since __del__ checks it

def __init__(self, args, bufsize=-1, executable=None,

stdin=None, stdout=None, stderr=None,

preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,

shell=False, cwd=None, env=None, universal_newlines=False,

startupinfo=None, creationflags=0,

restore_signals=True, start_new_session=False,

pass_fds=(), *, encoding=None, errors=None):

"""Create new Popen instance."""

_cleanup()

# Held while anything is calling waitpid before returncode has been

# updated to prevent clobbering returncode if wait() or poll() are

# called from multiple threads at once. After acquiring the lock,

# code must re-check self.returncode to see if another thread just

# finished a waitpid() call.

self._waitpid_lock = threading.Lock()

代码修改后:

# 部分代码

_child_created = False # Set here since __del__ checks it

def __init__(self, args, bufsize=-1, executable=None,

stdin=None, stdout=None, stderr=None,

preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,

shell=False, cwd=None, env=None, universal_newlines=False,

startupinfo=None, creationflags=0,

restore_signals=True, start_new_session=False,

pass_fds=(), *, encoding="utf-8", errors=None):

"""Create new Popen instance."""

_cleanup()

# Held while anything is calling waitpid before returncode has been

# updated to prevent clobbering returncode if wait() or poll() are

# called from multiple threads at once. After acquiring the lock,

# code must re-check self.returncode to see if another thread just

# finished a waitpid() call.

self._waitpid_lock = threading.Lock()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值