从rest api json返回的双精度值与从python应用引擎应用程序进行的调用不同

问题描述

我正在使用google rest api从内置于python2.7(标准env)的google app引擎中收集项目中实例的cpu利用率等指标。该实现基于google提供的以下代码

https://github.com/GoogleCloudplatform/stackdriver-metrics-export

用于收集cpu使用率指标的应用引擎代码如下:

from googleapiclient.discovery import build

service = build('monitoring','v3',cache_discovery=True)
timeseries = service.projects().timeSeries().list(
            name="my-project",filter="metric.type=compute.googleapis.com/instance/cpu/utilization"
            aggregation_alignmentPeriod=86400s,aggregation_perSeriesAligner="ALIGN_MEAN",aggregation_groupByFields="metric.labels.key",interval_endTime="2020-08-23T17:30:04.707Z",interval_startTime="2020-08-22T17:30:05.603000Z",pageSize=100
        ).execute()

它像这样形成一个REST API

https://monitoring.googleapis.com/v3/projects/my-project/timeSeries?pageSize=500&interval.startTime=2020-08-22T17%3A30%3A05.603000Z&aggregation.alignmentPeriod=86400s&aggregation.perSeriesAligner=ALIGN_MEAN&filter=metric.type%3D%22compute.googleapis.com%2Finstance%2Fcpu%2Futilization%22+&pagetoken=&interval.endTime=2020-08-23T17%3A30%3A04.707Z&alt=json&aggregation.groupByFields=metric.labels.key

如果我在诸如邮递员之类的工具中尝试其余api,或者直接在shell编辑器中尝试python代码,则对于邮递员,我将获得json格式的metric值;对于shell编辑器,将获得unicode格式的正确值:>

“值”:{ “ doubleValue”:0.87114489514772131 }

但是,当从基于python的google app引擎应用程序执行相同的代码时, timeseries 变量中包含的响应将返回 unicode 格式的值,该值存在差异
“值”:{ “ doubleValue”:0.8709659701719485 } 更新 大多数实例的几乎所有指标值都在发生这种情况。 来自其他api的double值以 json 格式出现,而从应用程序引擎调用的值以 unicode 格式出现,并且在Cloud Shell编辑器中它们以 unicode 格式,但它们与其余api值匹配 我真的是Google App Engine和python2.7的新手。谁能帮忙吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)