0

I'm having an issue with the following, error - think it's a case of the text containing ascii instead of utf-8 or something similar, but I'm not sure how to convert it in order to pass on to the rest of the code. Please also note that I'm limited to the python addons I can use so I have listed the imported ones at the top of the code. The error itself is here and any advice anyone could offer is very much appreciated:

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<--

The entirety of the code I've been using is as follows:

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
leopheard
  • 101
  • 7
  • 1
    At the line where the exception happens, you are trying to paste the representation of the entire soup object into a formatted string. Is that intentional? Looks like a bug to me... – lenz Jul 14 '20 at 11:34
  • Not sure about the soup object, but I'm trying to pass on the three results (url, title, thumbnail) into the next part of the code. I don't know a lot about BeautifulSoup TBH. – leopheard Jul 15 '20 at 14:55
  • The offending line says `if link.endswith("ttag=season:{}".format(soup1)):` (check the traceback). I guess that you really want to have something more specific in that format string. – lenz Jul 15 '20 at 17:00
  • @lenz TBH I'm not really sure what to add and unsure why it's fine with the data before I added the season filter, can I force BS to use ascii? – leopheard Jul 16 '20 at 03:08
  • `soup1` is the entire document. What value do you want to have for the season? – lenz Jul 16 '20 at 06:12

0 Answers0