Json 属性错误:';模块';对象没有属性';转储文件';(已检查文件)

Json 属性错误:';模块';对象没有属性';转储文件';(已检查文件),json,python-2.7,import,attributeerror,Json,Python 2.7,Import,Attributeerror,我试图用JSON文件配置一个帐户,但它给出了AttributeError。我已经检查了它导入的JSON的位置。我已经摆弄这几天了,我似乎找不到这个问题的根源。JSON中的\uuuu init\uuuu.py文件中定义了一个dumps函数。我是python新手,所以如果我忽略了其中的一个错误或者存在格式问题,我想提前道歉。多谢各位 输入: import sys import json import time import Adafruit_GPIO.SPI as SPI import Adafru

我试图用JSON文件配置一个帐户,但它给出了AttributeError。我已经检查了它导入的JSON的位置。我已经摆弄这几天了,我似乎找不到这个问题的根源。JSON中的
\uuuu init\uuuu.py文件
中定义了一个dumps函数。我是python新手,所以如果我忽略了其中的一个错误或者存在格式问题,我想提前道歉。多谢各位

输入:

import sys
import json
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855

__Author__ = 'Zach'

CLK = 11
DO = 25

sensor1 = MAX31855.MAX31855(CLK, 13, DO)
sensor2 = MAX31855.MAX31855(CLK, 29, DO)
sensor3 = MAX31855.MAX31855(CLK, 05, DO)
sensor4 = MAX31855.MAX31855(CLK, 06, DO)
sensor5 = MAX31855.MAX31855(CLK, 20, DO)
sensor6 = MAX31855.MAX31855(CLK, 21, DO)
sensor7 = MAX31855.MAX31855(CLK, 12, DO)
sensor8 = MAX31855.MAX31855(CLK, 16, DO)

try:
    config_data = open('/home/pi/TempMonitor/picloud_config.json').read()
    config = json.loads(config_data)
except:
    print 'Failed to load config data from picloud_config.json.  Exiting.'
    raise

host = config['aggregate_host']
room = config['room']
location = config['location']
api_key = config['api_key']
app_key = config['app_key']
dc = config['dc']

options = {
    'api_key': api_key,
    'app_key': app_key
}

tags = [
    'dc:' + dc,
    'room:' + room,
    'location:' + location
]

from datadog import initialize
from datadog import api
initialize(**options)

print('Press Ctrl-C to quit.')

print json
temp1 = float(sensor1.readTempC())
print('T1: {0:0.3F}*C'.format(temp1))
api.Metric.send(metric='sls.p7.temperature1', points=temp1, host=host, tags=tags)
temp2 = float(sensor2.readTempC())
print('T2: {0:0.3F}*C'.format(temp2))
api.Metric.send(metric='sls.p7.temperature2', points=temp2, host=host, tags=tags)
temp3 = float(sensor3.readTempC())
print('T3: {0:0.3F}*C'.format(temp3))
api.Metric.send(metric='sls.p7.temperature3', points=temp3, host=host, tags=tags)
temp4 = float(sensor4.readTempC())
print('T4: {0:0.3F}*C'.format(temp4))
api.Metric.send(metric='sls.p7.temperature4', points=temp4, host=host, tags=tags)
temp5 = float(sensor5.readTempC())
print('T5: {0:0.3F}*C'.format(temp5))
api.Metric.send(metric='sls.p7.temperature5', points=temp5, host=host, tags=tags)
temp6 = float(sensor6.readTempC())
print('T6: {0:0.3F}*C'.format(temp6))
api.Metric.send(metric='sls.p7.temperature6', points=temp6, host=host, tags=tags)
temp7 = float(sensor7.readTempC())
print('T7: {0:0.3F}*C'.format(temp7))
api.Metric.send(metric='sls.p7.temperature7', points=temp7, host=host, tags=tags)
temp8 = float(sensor8.readTempC())
print('T8: {0:0.3F}*C'.format(temp8))
api.Metric.send(metric='sls.p7.temperature8', points=temp8, host=host, tags=tags)
输出:

<module 'json' from '/usr/lib/python2.7/json/__init__.py'>
T1: NAN*C
Traceback (most recent call last):
  File "gather_temps.py", line 56, in <module>
    api.Metric.send(metric='sls.p7.temperature1', points=temp1, host=host, tags=tags)
  File "/usr/local/lib/python2.7/dist-packages/datadog/api/metrics.py", line 120, in send
    return super(Metric, cls).send(attach_host_name=True, **metrics_dict)
  File "/usr/local/lib/python2.7/dist-packages/datadog/api/resources.py", line 68, in send
    attach_host_name=attach_host_name)
  File "/usr/local/lib/python2.7/dist-packages/datadog/api/api_client.py", line 112, in submit
    body = json.dumps(body)
AttributeError: 'module' object has no attribute 'dumps'

T1:NAN*C
回溯(最近一次呼叫最后一次):
文件“collect_temps.py”,第56行,在
api.Metric.send(Metric='sls.p7.temperature1',points=temp1,host=host,tags=tags)
文件“/usr/local/lib/python2.7/dist packages/datadog/api/metrics.py”,第120行,在send中
返回super(Metric,cls).send(attach\u host\u name=True,**metrics\u dict)
文件“/usr/local/lib/python2.7/dist packages/datadog/api/resources.py”,第68行,在send中
附加主机名称=附加主机名称)
文件“/usr/local/lib/python2.7/dist packages/datadog/api/api_client.py”,第112行,提交
body=json.dumps(body)
AttributeError:“模块”对象没有属性“转储”

我注意到的一件事是,您的输出表明temp1是
NAN
,这意味着不是一个数字。我想您的
temp1=float(sensor1.readTempC())
出现了一些问题。修复此错误也可能会无意中修复JSON错误,因为
api.Metric.send
可能(很可能)假定输入正确(而不是
NAN
)。

因此问题在于Datadog目录中有一些文件进入了错误的文件夹。在卸载和重新安装一些目录之后。我让它工作得很好。

我以init.py的形式编写了它,我不知道为什么要更改它。它也在这里被修改了,但是在init文件中有下划线。对于类似这样的问题,通常的解释是,您在某个地方有一个名为json.py的文件,它位于真正的json模块之前。使用
导入json;打印json.\uuuuu文件\uuuuu
以查看其位置。@jasonharper感谢您检查我的问题。我确实检查了它,它给了我一个答案,说它正在使用定义的转储函数找到正确的文件。NAN只是我的温度传感器的读数。我先把它插上电源,然后运行,但它也有同样的问题。如果我连接热电偶,它会给我一个数字,但没有热电偶,它只是一个NAN。