首页 > 解决方案 > 带有“ascii”python 输出的 Unicode/解码错误

问题描述

我遇到了以下错误的问题 - 认为这是包含 ascii 而不是 utf-8 或类似内容的文本的情况,但我不知道如何转换它以传递给其余的代码。另请注意,我仅限于可以使用的 python 插件,因此我在代码顶部列出了导入的插件。错误本身就在这里,非常感谢任何人提供的任何建议:

Error Type: <type 'exceptions.UnicodeDecodeError'>
Error Contents: 'ascii' codec can't decode byte 0xc3 in position 986: ordinal not in range(128)
File ".../mainaddon.py", line 56, in get_playable_podcast1
if link.endswith("ttag=season:{}".format(soup1)):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 986: ordinal not in range(128)
-->End of Python script error report<--

我一直在使用的全部代码如下:

import requests
import re
from bs4 import BeautifulSoup

def get_playable_podcast1(soup1):
    subjects = []
    for content in soup1.find_all('item'):
        try:
            title = content.find('title')
            title = title.get_text()
            link = content.find('enclosure')
            link = link.get('url')
            if link.endswith("ttag=season:{}".format(soup1)):
                urls.append(link) 
        except AttributeError:
            continue
        return subjects
        continue
        item = {
                    'url': link,
                    'title': title,
                    'thumbnail': "..imagehere",
            }
        subjects.append(item)
        return subjects
def compile_playable_podcast1(playable_podcast1):
    items = []
    for podcast in playable_podcast1:
        items.append({
            'label': podcast['title'],
            'thumbnail': podcast['thumbnail'],
            'path': podcast['url'],
            'is_playable': True,
    })
    return items

标签: pythonparsingutf-8asciikodi

解决方案


推荐阅读