首页 > 编程语言 > 详细

python2 中字符串转成字典后汉字出现乱码

时间:2020-03-09 21:52:43      阅读:111      评论:0      收藏:0      [点我收藏+]
#!/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

python2 中字符串转成字典后汉字出现乱码

原文:https://www.cnblogs.com/leleyao/p/12450987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!