That means the note text files have an encoding that is not 'utf8'. You have to figure out that encoding your text editor save with, which depends on what language you are using for these, and add the proper encoding as follows (added bit are highlighted in
red):
Code:
import regex
fmt = 'TXT'
def run(gui, settings, chain):
#db = DB(library_path)
db = gui.current_db
book_ids = db.data.search_getting_ids('series_index:=9999999', None)
for book_id in book_ids:
path_to_book = db.format_abspath(book_id, fmt, index_is_id=True)
title = db.title(book_id, index_is_id=True)
series_name = db.new_api.field_for('series', book_id)
print(f'Book title: {title} | Series: {series_name}')
if not path_to_book:
print(f'Book does not have format: {fmt}')
continue
with open(path_to_book, 'r', encoding='insert_proper_encoding_here') as f:
note = regex.sub(r'http[^\s]+', r'', f.read())
series_id = db.new_api.get_item_id('series', series_name)
print(f'series_id: {series_id} | note: {note}')
db.new_api.set_notes_for('series', series_id, note)