0

マシン上で jenkins ユーザーとして正常に実行できる Python スクリプトがあります。jenkins Web フロントエンドを使用してジョブをマシン上で実行するように構成する場合、実行するジョブとして Python スクリプトを指定します。何らかの理由で、私は Python のコンテキストでは意味をなさない最も奇妙な KeyError を取得します。

    log_name = '-'.join([status_map[test.status], test.config[0], test.config[1], test.group_raw+'.'+test.title])+'.log'
KeyError: 'error: failed to open driver pseudo terminal : Device not configuredFAILURE'

エラー メッセージの末尾に追加された「FAILURE」は、実際には、このエラーがスローされた行の status_map で検索されている test.status の値です。しかし、コードが適切であると判断できる限り、エラーは発生しないはずです。また、コマンド ラインから自分で実行すると、スクリプトは問題なく実行されます。問題は何でしょうか?

4

2 に答える 2

0
log_name = '-'.join([status_map[test.status], test.config[0], test.config[1], test.group_raw+'.'+test.title])+'.log'
KeyError: 'error: failed to open driver pseudo terminal : Device not configuredFAILURE'

dict の最初のキーが存在するかどうかを確認する必要があります。最初にtest.statusキーをstatus_map.has_key(test.status)を使用してstatus_mapに存在するかどうかを確認します

if status_map.has_key(test.status):
    log_name = '-'.join([status_map[test.status], test.config[0], test.config[1], str(test.group_raw)+'.'+test.title])+'.log'
于 2013-10-15T06:54:19.710 に答える
0

という名前の変数がtest.statusあり、その値はerror: failed to open driver pseudo terminal : Device not configuredFAILURE

しかし、dictstatus_mapにはそのようなキーが含まれていないため、この dict に test.status キーでアクセスすると keyError が発生します。

status_map[test.status]

KeyError: 'error: failed to open driver pseudo terminal : Device not configuredFAILURE'
于 2013-10-15T05:53:12.197 に答える