2017-11-14 6 views
0

デフメイン(TARGET_DB)でなければなりません:JSONはstrのバイトではありません

# get available logs 

output = subprocess.Popen(['aws','rds', 'describe-db-log-files', '--db-instance-identifier', target_db],stdout=subprocess.PIPE).communicate()[0] 

dict_output = json.loads(output) 
log_file_names = map(lambda l:l['LogFileName'], dict_output['DescribeDBLogFiles']) 

mkdir_p('logs/error') 

# aws rds download-db-log-file-portion --db-instance-identifier prod-api --log-file-name error/postgresql.log.2015-04-20-18 --output text > logs/error/postgresql.log.2015-04-20-18 
for log_file_name in log_file_names: 
    content = subprocess.Popen(['aws','rds', 'download-db-log-file-portion', '--db-instance-identifier', target_db, '--log-file-name', log_file_name, '--output', 'text'],stdout=subprocess.PIPE).communicate()[0] 
    with open('logs/%s' % log_file_name, 'wb') as fw: 
     fw.write(content) 

私はそれがJSONオブジェクト(dict_output =としてロードラインでスクリプトを実行中にエラーJSONがないバイトをstrする必要があります取得していますjson.loads(出力))。

+0

あなたが使用している 'python version'は何ですか?設定した' aws cli output format'は何ですか? –

+0

サブプロストを作成するのではなく、boto3ライブラリを活用して操作を実行することをお勧めします。http://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.download_db_log_file_portion and http: /boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.describe_db_log_files –

+0

pythonバージョンは3.4.3です。 –

答えて

0

まず、そのようなプリントタイプにしてみてください:

print type(output)

それが文字列でない場合は、これを使用して文字列に変換しよう:

output = str(output)またはdict_output = json.loads(str(output))

・ホープ、この意志を助けて。

関連する問題