[英]json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig)
[英]Unable to resolve “json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig) error”.Can anyone assist?
我正在尝试访问S3存储桶(这是一个JSON文件)中的对象,并试图在Visual Studio代码中打开它。 但是我收到错误消息“ json.decoder.JSONDecodeError:意外的UTF-8 BOM(使用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)
decode()
默认编码为utf-8
。 追溯指定文件的编码为utf-8 BOM
因此您需要将utf-8-sig
传递给decode()
,例如
file_content = content_object.get()['Body'].read().decode('utf-8-sig')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.