首页 > 编程语言 >python 运行 execjs 出现错误 UnicodeEncodeError: 'gbk' codec can't encode character '

python 运行 execjs 出现错误 UnicodeEncodeError: 'gbk' codec can't encode character '

时间:2023-08-16 20:55:06浏览次数:49  
标签:文件 None encoding python xfe character gbk execjs

异常解读

该异常的格式一般为:

UnicodeEncodeError: 'gbk' codec can't encode character '\xfe' in positio

该异常出现的场景为在 Windows 电脑下使用 Python execjs 运行指定的 JS 文件,但 JS 文件中包含中文。

异常解决方案

该问题解决需要 修改 你电脑 Python 安装目录下 lib 文件夹里面的一个文件,名字叫做 subprocess.py

例如在我本地为 :

 通过任意文本编辑器打开该文件,在文件中检索 encoding,找到如下位置:

修改 encoding=None 为 encoding = "utf-8" 。

    def __init__(self, args, bufsize=-1, executable=None,
                 stdin=None, stdout=None, stderr=None,
                 preexec_fn=None, close_fds=True,
                 shell=False, cwd=None, env=None, universal_newlines=None,
                 startupinfo=None, creationflags=0,
                 restore_signals=True, start_new_session=False,
                 pass_fds=(), *, encoding="utf-8", errors=None, text=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()

保存文件,解决问题。

标签:文件,None,encoding,python,xfe,character,gbk,execjs
From: https://www.cnblogs.com/yoyo1216/p/17636152.html

相关文章

  • 软件测试|docker搭建Jenkins+Python+allure自动化测试环境
    简介本文将详细介绍如何使用Docker搭建一个完整的自动化测试环境,其中包括Jenkins作为持续集成和持续交付工具,Python作为测试脚本编写语言,以及Allure作为测试报告生成工具。通过使用Docker容器,您可以轻松地设置和管理这些工具,提高测试效率和质量。安装docker安装docker的步骤,可以直......
  • Python的循环语句
    循环语句可以让我们的代码重复的去执行while循环:  while条件:    代码 过程:判断while循环的条件是否为真,如果真,执行代码.然后再次判断条件.....直到条件为假循环结束案例1:whileTrue:#死循环print("喷死你")以上这段代码是一个死循环,因为判断......
  • Python 自定义运算符
    Python自定义运算符正向运算符+__add__(self,other)-__sub__(self,other)*__mul__(self,other)/__truediv__(self,other)//__floordiv__(self,other)%__mod__(self,other)**__pow__(self,other)<__lt__(self,other)>__gt__(self,other)==__......
  • Python学习日记 2023年8月16日
    fromseleniumimportwebdriver##pipinstallseleniumfromtimeimportsleepimportcsvf=open('口红1.csv',mode='a',encoding='utf-8',newline='')#csv.DictWriter字典写入csv_writer=csv.DictWriter(f,fieldnames=[......
  • pythonOCC 将二维坐标转化为三维坐标
    OCC当中提供了多种方式转换直接转换为三维坐标使用V3d_View.ProjReferenceAxe()会返回有6个元素的元组,前三位分别对应XYZ例子self._display.View.ProjReferenceAxe()但是,这种方式转换的坐标让人有点摸不着头脑,不推荐 通过求交点获取这种方式会把鼠标限制与某一个面上,......
  • 拿到开发板需要做的事情 -- 配置Python环境
    1.查看系统时间date-R 2.修改系统时间windows上时间项目时间正常,Ubuntu16.04上时间错误-贾斯丁哔哔-博客园(cnblogs.com) 3.安装pip3sudoapt-getupdatesudoapt-getinstallpython3-pip ......
  • python类型标注self
    起因假设有如下代码,我想标注类方法的返回值为自己本身classQueue:def__init__(self):self.items=[]defenqueue(self,item)->Queue:self.items.append(item)returnself用Queue来标注返回值类型,但是呢,运行时Python会报错Traceb......
  • python中自定义类对象json字符串化的方法
    1.用json或者simplejson就可以2.定义转换函数:defconvert_to_builtin_type(obj):print'default(',repr(obj),')'#把MyObj对象转换成dict类型的对象d={}d.update(obj.__dict__)returnd 3.定义类classObject():name=""size=0def__init__(......
  • python不同包之间调用提示不存在
     python不同包之间调用提示不存在 在file-setting-project-projectSources,把包放入到Sources中 再次查看,正常 ......
  • 常用文件读取(python)
    CSV文件CSV(Comma-SeparatedValues)是一种常见的文本文件格式,用于存储结构化的数据。CSV文件中的数据是以逗号(或其他指定的分隔符)分隔的文本行,每一行表示一条记录,每个字段表示记录中的一个属性或值。读CSVimportcsvimportcodecsfile_name=""withopen(file_name,"r",en......