问题描述
我正在尝试将curl命令转换为python请求(使用urllib)。这是用于Promotheus推送网关的: https://github.com/prometheus/pushgateway
可以使用curl使用以下方式将数据发布到链接: some_metric {label =“ val1”} 42
示例: CountRec {studentname =“ John”,subject =“ English”,subjectcode =“ DU12345678999”,system =“ pythonETL”} 40
但是我没有得到如何使用python和值40进行发布
以下是我尝试的代码: url ='http:// host:port / metrics / job / jobname / instance / host:port'
myRestRequestObj = urllib.request.Request(url)
myRestRequestObj.add_header('Content-Type','application/json')
myRestRequestObj.get_method = lambda : 'PUT'
myStringJson={'CountRec{"studentname":"John","subject"="English","subjectcode"="DU12345678999","system"="pythonETL"} 40}'
data=urllib.parse.urlencode(myStringJson)
data1 = data.encode('ascii')
res = urllib.request.urlopen(myRestRequestObj,data1)
rest_txt=res.read().decode('utf-8')
return ast.literal_eval(rest_txt)
但是我遇到错误,说它不是有效的非字符串序列或映射对象。
请帮助我解决这个问题:)预先感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)