从DynamoDB提取数据时遇到的错误;
UnicodeEncodeError:'charmap'编解码器无法对位置1761处的字符'\ u2019'进行编码:字符映射至
代码;
self.db = boto3.resource(
'dynamodb',
region_name=Config.AWS_DB_REGION_NAME,
aws_access_key_id=Config.AWS_DB_ACCESS_KEY,
aws_secret_access_key=Config.AWS_DB_SECRET_KEY
)
self.tableName = "test"
queryAll():
self.actionTable = self.db.Table(self.tableName)
query = self.actionTable.scan(
ProjectionExpression='id, cityName, title, lat, lng',
FilterExpression=Attr("type").eq("attraction")
)
return query
venues = queryAll()
print("Found Records: {}\n".format(str(venues['Count']) + "/" +
str(venues['ScannedCount'])))
founds = list()
if venues['Count']:
for i, item in enumerate(venues['Items']):
if "lat" in item:
founds.append(
{
"id": item["id"],
"title": str(item["title"]),
"location": str(item['lat']) + "," + str(item['lng'])
})
print(founds)
Items = venues['Items']
exit()
答案 0 :(得分:0)
解决此功能的问题
.encode('ascii','ignore').decode()
使用;
"title": str(item["title"]).encode('ascii','ignore').decode(),