raise ProcessExitedWithNonZeroStatus python问题

项目场景:

问题:python使用execjs调用js文件报错:raise ProcessExitedWithNonZeroStatus


问题描述

提示:这里描述项目中遇到的问题:

控制台报错:

Traceback (most recent call last):
  File "c:\Users\mgoo1\Desktop\hxxxxx\python\exportData\����ѧϰ\xiaomanNXJs\testGetToken.py", line 35, in <module>
    result = js_compiled.call('generateSignature',params,token)
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_abstract_runtime_context.py", line 37, in call
    return self._call(name, *args)
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_external_runtime.py", line 92, in _call
    return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_external_runtime.py", line 78, in _eval
    return self.exec_(code)
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
    return self._exec_(source)
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_external_runtime.py", line 87, in _exec_
    output = self._exec_with_pipe(source)
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_external_runtime.py", line 108, in _exec_with_pipe
    self._fail_on_non_zero_status(ret, stdoutdata, stderrdata)
  File "C:\Users\mgoo1\AppData\Roaming\Python\Python38\site-packages\execjs\_external_runtime.py", line 134, in _fail_on_non_zero_status
    raise ProcessExitedWithNonZeroStatus(status=status, stdout=stdoutdata, stderr=stderrdata)
execjs._exceptions.ProcessExitedWithNonZeroStatus: (1, '', "[stdin]:3\nimport cryptoJs from 'crypto-js';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n    at new Script (vm.js:101:7)\n    at createScript (vm.js:262:10)\n    at Object.runInThisContext (vm.js:310:10)\n    at internal/process/execution.js:77:19\n    at [stdin]-wrapper:6:22\n    at evalScript (internal/process/execution.js:76:60)\n    at internal/main/eval_stdin.js:29:5\n    at Socket.<anonymous> (internal/process/execution.js:205:5)\n    at Socket.emit (events.js:327:22)\n    at endReadableNT (internal/streams/readable.js:1327:12)\n")

原因分析:

提示:这里填写问题的分析:

js文件中,使用了 import***from*** 的方法,配合package.json配置文件来可以正常运行。去掉配置文件会发现,单独运行js文件也会报错和在python中调用一样的错。


// const cryptoJs = require('crypto-js')
import cryptoJs from 'crypto-js';

解决方案:

将js文件中使用import引入方式改一下即可


 const cryptoJs = require('crypto-js')
// import cryptoJs from 'crypto-js';
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值