Ошибка в кодировке python
Помогите как решить проблему ? это мой первый код на python...
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import csv
import os
URL = 'https://auto.ria.com/newauto/marka-jeep/'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0', 'accept': '*/*'}
HOST = 'https://auto.ria.com'
FILE = 'cars.csv'
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('a', class_='na-card-item')
cars = []
for item in items:
cars.append({
'title': item.find('div', class_='na-card-name').get_text(strip=True),
'link': HOST + item.find('span', class_='link').get('href'),
'usd_price': item.find('strong', class_='green').get_text(),
'city': item.find('svg', class_='svg_i16_pin').find_next('span').get_text(),
})
return cars
def save_file(items, path):
with open(path, 'w') as file:
writer = csv.writer(file, delimiter=';')
writer.writerow(['name'])
for item in items:
writer.writerow([item['title']])
def parse():
html = get_html(URL)
if html.status_code == 200:
cars = get_content(html.text)
save_file(cars, FILE)
else:
print('Error')
parse()
ошибка выползает
Traceback (most recent call last):
File "parser.py", line 51, in <module>
parse()
File "parser.py", line 46, in parse
save_file(cars, FILE)
File "parser.py", line 39, in save_file
writer.writerow([item['title']])
UnicodeEncodeError: 'ascii' codec can't encode characters in position 26-27: ordinal not in range(128)