创建临时文件存放证书之类
2018-06-15 本文已影响0人
老周_o_o
参考文章:https://www.jianshu.com/writer#/notebooks/26334576/notes/29530698
def write_cert():
TEMP = tempfile.mkdtemp(suffix='_py', prefix='learn_python_') # 每次都会新建一个临时文件夹,也可以用mkstemp创建临时文件
fpath = os.path.join(TEMP, 'local.liaoxuefeng.com.pem')
# fpath = "/var/folders/6j/2yp3ybgd227cf8m7b0swgl2w0000gn/T/learn_python_59dp48tf_py/local.liaoxuefeng.com.pem"
with open(fpath, 'w', encoding='utf-8') as f:
f.write(CERT_DATA)
return fpath
CERT_DATA = "xxxxxx"