之前申请了腾讯的云函数,打一直没怎么用过.
最近买了个东西,想用云函数定时给我发送物流信息的邮件.
但是总是测试失败……
程序在运行的时候是正常的,但是每次部署完测试的时候总是失败,提示我找不到bs4,求大神们帮我看一下有什么问题,解决一下.
另外关于云函数的使用有什么需要注意的也可以指点一下
求帮助
下面贴错误截图和代码
测试返回结果
mess.py:
[Python] 纯文本查看 复制代码 import requests as req
from bs4 import BeautifulSoup as bef
import time
import sys
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
def m():
url = "https://consignee.ecmsglobal.com/brige/showtracking?lang=zh&trackingno=订单号"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
}
r = req.get(url, headers)
html = r.text
t = bef(html, 'html.parser')
where = t.find_all(name="div", attrs={"class": "e-route-process"})
ti = t.find_all(name="div", attrs={"class": "time"})
s = ""
for k, l in zip(where, ti):
n = k.find('p')
#print(l.string)
# print(n.string.text.strip().split('\xa0'))
s = s+'\n'+l.string+'\n'+n.string.strip()+'\n['
time_str = time.strftime('%Y年%m月%d日%H时%M分%S秒')
#print(time_str+'\n'+s)
return time_str+'\n'+s
if __name__ == '__main__':
print(m())
mail.py:
[Python] 纯文本查看 复制代码 import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
from mess import m
my_sender='*@qq.com'
my_pass = '*'
my_user='*'
def smail():
ret=True
s=m()
try:
msg=MIMEText(s,'plain','utf-8')
msg['From']=formataddr(["来自自动发送",my_sender])
msg['To']=formataddr(["FK",my_user])
msg['Subject']="日程"
server=smtplib.SMTP_SSL("smtp.qq.com", 465)
server.login(my_sender, my_pass)
server.sendmail(my_sender,[my_user,],msg.as_string())
server.quit()
except Exception:
ret=False
return ret
if __name__ == '__main__':
smail()
index.py:
[Python] 纯文本查看 复制代码 # -*- coding: utf8 -*-
import json
from mail import smail
def main_handler(event, context):
smail()
print("成功")
if __name__ == '__main__':
main_handler("key1","test value 1")
|