我想将json数据写入.csv文件,但出现此错误
UnicodeEncodeError:'ascii'编解码器无法在位置9编码字符u'\ U0001f61c':序数不在范围内(128)
这是我的代码
import os
import json
import facebook
import csv
import pandas as pd
from pandas.io.json import json_normalize
output_file = open("posts.csv", "w")
writer = csv.writer(output_file)
if __name__ == "__main__":
token = os.environ.get("FACEBOOK_TEMP_TOKEN")
graph = facebook.GraphAPI(access_token=token)
profile = graph.get_object('me/posts',fields = 'message, description')
#[x['id'] for x in profile['friends']['data']]
json_data = json.dumps(profile, indent=4)
json_data_ = json.loads(json_data)
for distro in json_data_["data"]:
writer.writerow(distro.values())