A-A+

百度云函数 No module named ModuleNotFoundError 解决方案

2021年04月12日 22:48 学习笔记 暂无评论 共1670字 (阅读1,753 views次)

【注意:此文章为博主原创文章!转载需注意,请带原文链接,至少也要是txt格式!】

百度云函数相对TX云函数还是稍微人性化一些些的。不过今天在部署脚本的时候发现百度云函数 python内置的库真的少的可怜哦。在执行代码的时候爆如下错误

 
此区域下方显示你的函数执行的结果。

{
    "errorMessage": "No module named 'pyDes'",
    "errorType": "ModuleNotFoundError"
}

  
此区域下方显示你的函数执行过程中产生的日志。

START RequestId: 8e2c7a58-1c27-4984-b4d9-eacxxxxb529c Version: $LATEST
Traceback (most recent call last):
  File "/var/runtime/lib/python3.6/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/runtime/lib/python3.6/imp.py", line 172, in load_source
    module = _load(spec)
  File "", line 675, in _load
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in _call_with_frames_removed
  File "/var/task/index.py", line 6, in 
    from pyDes import des, PAD_PKCS5, ECB
ModuleNotFoundError: No module named 'pyDes'
END RequestId: 8e2c7a58-1c27-4984-b4d9-eac0xxxx9c
REPORT RequestId: 8e2c7a58-1c27-4984-b4d9-eacxxxx529c	Duration: 345ms	Billed Duration: 400ms	Max Memory Used: 6.1M

跟腾讯云一样明显是没有这个模块,但是百度人性化在,你可以下载整个包,如图:

百度云函数 文件打包下载

下载后把所需要的库上传至这个zip包中,要注意你index.py调用的路径哦。相当于他们在同一个工作目录中。然后正常引用即可。
然后上传你修改后的zip包。 在次测试就会成功了。

下面是成功的信息:

执行结果:成功
此区域下方显示你的函数执行的结果。

{"code": 10000, "data": {"isManHour": false}, "flag": "1", "msg": "xxxxxx"}

此区域下方显示你的函数执行过程中产生的日志。


START RequestId: c21405ac-d47f-428e-8d87-f4xxxx1 Version: $LATEST
/var/runtime/lib/python3.6/site-packages/urllib3/connectionpool.py:988: InsecureRequestWarning: Unverified HTTPS request is being made to host 'rxxxxxx.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
END RequestId: c21405ac-d47f-428e-8d87-f4xxxxx261
REPORT RequestId: c21405ac-d47f-428e-8d87-f45xxxxx61	Duration: 2.03s	Billed Duration: 2.1s	Max Memory Used: 14.2M

布施恩德可便相知重

微信扫一扫打赏

支付宝扫一扫打赏

×

给我留言