WSGI接口:实现从浏览器访问运行python程序--显示更加动态的参数03

2021/7/28 17:08:53

本文主要是介绍WSGI接口:实现从浏览器访问运行python程序--显示更加动态的参数03,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

实现的功能如下

1.运行自己写的python程序(.py),将此程序作为服务器监听

2.从浏览器输入相应的ip,端口,这里还实现了输入相应的参数,可以传递参数并运行.py程序

3.运行程序后,实现电子邮件加密后发送

 

 服务器端:

# 编写人:Jaoany
# 开发时间:2021/7/27 15:01
from flask import Flask
from flask import request

# 发送邮件,使用RSA密码算法加密,需要接收方使用自己的私钥对密文解密
# 导入第三方模块
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

print("Content-type:text/html")

# 在这里可以自己写函数

app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def home():
    return '<h1>Home</h1>'

#如果想动态传参数,在"/sender"后面添加"/<plaintext1>",然后你就可以引用了
@app.route("/sender/<plaintext1>", methods=['GET'])
def sender(plaintext1):
    p, q, e = make_p_q_e()
    # 获取数据
    # plaintext1 = input("待发送加密数据:")
    # plaintext1 = '1234567'
    # 将输入的数据转换成01字符串
    plaintext = ' '.join(format(ord(x), 'b') for x in plaintext1)
    # 公钥、私钥
    public_key, private_key = make_key(p, q, e)
    # 加密
    ciphertext1 = encryption(public_key, plaintext)
    print("加密后的数据:", ciphertext1)
    # 将数组转换成字符串
    ciphertext = ', '.join(str(i) for i in ciphertext1)
    # 输出加密后的字符串数据
    print(ciphertext)
    # 调用函数(登录密码需要换成你自己的)
    mail('发件人邮箱@qq.com', '发件人邮箱SMTP验证码', '收件人邮箱.com', '发件人昵称', '收件人昵称', ciphertext)
    return '<h3>邮件发送成功! {}</h3>'.format(plaintext1)


if __name__ == '__main__':
    app.run()

 



这篇关于WSGI接口:实现从浏览器访问运行python程序--显示更加动态的参数03的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程