python - 带有“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
解决方案
推荐阅读
- python - 字符串中出现频率最高的数字
- java - 有没有更好的方法在读取下面的 arrayNode 时进行深度空点检查?
- java - 我对 androidф 谷歌地图上的标记有疑问
- python - 如何使用具有变化增量的辅助变量并行遍历两个列表?
- android - 如何使用 Ionic 和 Cordova 修复 Android 应用程序中的漏洞问题
- python - Jupyter notebook:即使关闭选项卡也需要运行一个单元格
- selenium - 需要为 Protractor 降级 chromedriver 以匹配早期的 Chrome 版本
- ms-access - 分解“不支持加入”代码,仍然遇到问题
- javascript - 如何在条件组件中处理 onClick 事件
- list - 有什么方法可以在 Flutter 中处理应用状态下的 List 吗?