1
运行,我有一个简单的脚本python3当我从控制台运行它的作品:Python3:configparser KeyError异常时作为的cronjob
import configparser
file = 'config_test.ini'
config = configparser.ConfigParser()
config.read(file)
for key in config['test_section']: print(key)
被叫ini文件看起来是这样的:
[test_section]
testkey1 = 5
testkey2 = 42878180
testkey3 = WR50MS10:1100
testkey4 = WR50MS04:1100012010
testkex5 = 192.168.200.168
并且脚本运行良好并返回ini文件的五个键。
没有我配置它作为一个cronjob通过每分钟(上树莓派rasbian运行):
* * * * * python3 /home/pi/s0/testconfig.py >> /tmp/cron_debug_log.log 2>&1
和日志看起来是这样的:
Traceback (most recent call last):
File "/home/pi/s0/testconfig.py", line 7, in <module>
for key in config['test_section']: print(key)
File "/usr/lib/python3.2/configparser.py", line 941, in __getitem__
raise KeyError(key)
KeyError: 'test_section'
有没有人有一个想法是什么我做错了 亲切的问候