python2 中字符串轉成字典后漢字出現亂碼


#!/bin/python
#coding=utf-8
import requests
import sys
import json
import time
msg=sys.argv[1]
with open('/tmp/log.txt','a+') as song:
  song.write(time.strftime('%Y-%m-%d %H:%M:%S'))
  song.write(msg)
  song.write('\n')

data=eval(msg)
#{"hostname":"Zabbix server","trggier_name":"sos測試","ip":"127.0.0.1"}

alert={}

alert["source"] = data["hostname"]
alert["title"] = data["trggier_name"]
alert["section"] = data["section"]
alert["group"] = "network"
alert["content"] = data["content"]
alert=json.dumps(alert,ensure_ascii=False)
requests.post('http://dingtalk.com', data=alert)
ensure_ascii=False


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM