I am continuously getting this type of error when writing parsed content to a csv in python 2.7: UnicodeEncodeError: 'ascii' codec can't encode characters in position 570-579: ordinal not in range(128)
So after some research I found the examples in the docs as well as a similar Question on SO: Read and Write CSV files including unicode with Python 2.7 but I couldn't get mine to work with the following code:
data = {
'scrapeUrl': url,
'model': final_model_num,
'title': final_name,
'description': final_description,
'price': str(final_price),
'image': final_first_image,
'additional_image': final_images,
'quantity': '1',
'subtract': '1',
'minimum': '1',
'status': '1',
'shipping': '1'
}
with open("local/file1.csv", "w") as f:
writer=csv.writer(f, delimiter=",")
writer.writerows([data.keys()])
for row in zip(*data.values()):
row=[s.encode('utf-8') for s in row]
writer.writerows([row])
My version seems to be writing only the first character of each variable to each row; I tried removing the unzip key as a bit of troubleshooting but that resulted in all of the data being printed correctly but to one column of the csv rather than one row.