Nobelz / RateMyProfessorAPI

Python web scraper to get professor ratings from ratemyprofessor.com website.
Apache License 2.0
39 stars 11 forks source link

AttributeError: 'NoneType' object has no attribute 'id' #11

Closed dfuentes87 closed 1 year ago

dfuentes87 commented 1 year ago

I'm using this tool in a Discord bot I wrote for my old community college. Packages are fine as far as RateMyProfessorAPI wants:

python3 -m pip install RateMyProfessorAPI --upgrade
Requirement already satisfied: RateMyProfessorAPI in /usr/local/lib/python3.9/dist-packages (1.3.3)
Requirement already satisfied: lxml in /usr/local/lib/python3.9/dist-packages (from RateMyProfessorAPI) (4.9.2)
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.9/dist-packages (from RateMyProfessorAPI) (4.11.1)
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from RateMyProfessorAPI) (2.25.1)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.9/dist-packages (from beautifulsoup4->RateMyProfessorAPI) (2.3.2.post1)

The issue started after the Discord bot was restarted two days ago:

Ignoring exception in command professor:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
  File "/usr/local/lib/python3.9/dist-packages/discord/commands/core.py", line 980, in _invoke
    await self.callback(ctx, **kwargs)
  File "/root/wtcc_bot/wtcc_bot.py", line 89, in professor
    await ctx.followup.send(embed=rmp_info.embed_builder(name))
  File "/root/wtcc_bot/rmp_info.py", line 9, in embed_builder
    professor = ratemyprofessor.get_professor_by_school_and_name(
  File "/usr/local/lib/python3.9/dist-packages/ratemyprofessor/__init__.py", line 80, in get_professor_by_school_and_name
    professors = get_professors_by_school_and_name(college, professor_name)
  File "/usr/local/lib/python3.9/dist-packages/ratemyprofessor/__init__.py", line 105, in get_professors_by_school_and_name
    "/search/teachers?query=%s&sid=%s" % (professor_name, base64.b64encode(("School-%s" % college.id)
AttributeError: 'NoneType' object has no attribute 'id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.9/dist-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'

This is how I have it in the bot code:

    professor = ratemyprofessor.get_professor_by_school_and_name(
        ratemyprofessor.get_school_by_name("Wake Technical Community College"), prof_name)
ozeitis commented 1 year ago

I fixed this in my latest proposed edit

12

Nobelz commented 1 year ago

Should be fixed in 1.3.4. Reopen if not