python3+requests接口自动-配置文件

1.cfg.ini打开,这里写配置文件内容

[email]
smtp_server = smtp.qq.com
port = 456
sender = [email protected]

;psw是邮箱的授权码
psw = xxx


receiver = [email protected]

2.用readConfig.py读取配置文件
 1 import os
 2 import ConfigParser
 3 
 4 cur_path = os.path.dirname(os.path.realpath(__file__))
 5 configPath = os.path.join(cur_path,"cfg.ini")
 6 conf = ConfigParser.ConfigParser()
 7 conf.read(configPath)
 8 
 9 smtp_server = conf.get("email","smtp_server")
10 
11 sender = conf.get("email","sender")
12 
13 psw = conf.get("email","psw")
14 
15 receiver = conf.get("email","receiver")
16 
17 port = conf.get("email","port")

3.读取的内容就是传入第二步操作里面需要调用邮箱的配置信息

猜你喜欢

转载自www.cnblogs.com/jayson-0425/p/9809681.html