raise ProcessExitedWithNonZeroStatus python问题

  • Post author:
  • Post category: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';



版权声明:本文为YouDage原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。