绝望,上传文件失败。。遇到并解决java.lang.NullPointerException

解决报错:java.lang.NullPointerException

解决方法:将文件的编码方式改为utf-8即可!

截图:

修改成功后:

 

代码:

import os
import json
import re
def json_to_html(i,cvenum):
    print('正在处理:'+cvenum)
    head = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>漏洞对应信息摘要 </title></head>" \
           "<body bgcolor='#faebd7'><h1 style='text-align:center'>cvesummary for this cve</h1><div style='color: #3e2c42; text-align: center; line-height: 35px;font-size: 20px;'>"
    tail = "</div></body></html>"#padding-left: 320px
    cvesummary_context = head + i + tail
    cvenum = str(cvenum)
    cvenum = cvenum.replace('-','')#去掉横杠
    with open('D:/0html/'+cvenum+'.html', "w", encoding='utf-8') as json_file:
        json_file.write(cvesummary_context)
        json_file.close()
    print('D:/0html/'+i+'.html')
def rewrite():
    global num
    cve_inf_file = open('试试.json', "r", encoding='utf-8')
    cve_inf_context = json.load(cve_inf_file)
    for i in cve_inf_context:
        # print(i)
        json_to_html(i['cvesummary'],i['Cve_ID'])#原本数据写为HTML,并以CVE编号命名!
        ss = re.findall('\d+.\d+', str(i['Cve_ID']))
        num += 1
        print('\n处理第'+str(num)+'个数据。其CVE编号为:'+ss[0]+'对应的json文件! 共计:'+str(sum)+'个json文件\n')
        ss = str(ss[0])
        ss = ss.replace('-', '')
        i['cvesummary'] = "<a href='http://39.100.231.197/cvesummary/"+ss+".html' target='_blank' title='转到"+ss+"所对应信息摘要'>"+"查看"+ss+"所对应信息摘要"+"</a>"
    with open('cve_addprod.json', "w",encoding='utf-8') as json_file:
        json_str = json.dumps(cve_inf_context, indent=4, ensure_ascii=False)
        json_file.write(json_str)
        json_file.close()
    print('\n\n成功存储:D:/0test/cve_addprod.json.  一共'+str(num)+"条数据!")
if __name__ == '__main__':
    global num
    num = 0
    rewrite()





发布了624 篇原创文章 · 获赞 1694 · 访问量 121万+

猜你喜欢

转载自blog.csdn.net/weixin_42859280/article/details/105521089