I am trying to access objects in S3 bucket which is a JSON file and tying to open it up in Visual Studio code. But I am getting error "json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig)"
import boto3
import json
import requests
boto3.setup_default_session(profile_name='rli-dev', region_name='us-west-2')
s3 = boto3.resource('s3')
content_object = s3.Object('bsdev-data-validation','awsnightlyendtoend_bsdev_2018-10-24T11:53:45Z/validate_adwactivityfact/job-details.json')
file_content = content_object.get()['Body'].read().decode()
json_content = json.loads(file_content)
print(json_content)
default encoding for decode()
is utf-8
. The traceback specify the encoding of the file is utf-8 BOM
thus you need to pass utf-8-sig
to decode()
, eg
file_content = content_object.get()['Body'].read().decode('utf-8-sig')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.