ArmindoFlores / ao3_api

An unofficial archiveofourown.org (AO3) API for python
MIT License
166 stars 64 forks source link

"UnboundLocalError: cannot access local variable 'workid' where it is not associated with a value" when listing bookmarks #99

Open anafvana opened 4 months ago

anafvana commented 4 months ago

A short prelude to say:

  1. Thank you SO MUCH for developing this package. I had almost lost hope that I'd manage to develop my pet script when I found this gem
  2. I discovered this repo about 30 minutes ago, so apologies if I'm missing something obvious

Summary

I'm trying to retrieve all my bookmarks, but I'm getting the following error:

UnboundLocalError: cannot access local variable 'workid' where it is not associated with a value

I suspect this is due to some of my bookmarked works only being available to registered users. HOWEVER, I am passing a session when creating a user, so I'd assume it should be able to use this session to also retrieve the bookmarks.

Code

username = "REDACTED_USERNAME"
session = AO3.Session(username=username, password="REDACTED_PASSWORD")
user = AO3.User(username=username, session=session)
bookmarks = user.get_bookmarks()

Additional Information

  1. I suspect this is due to a lack of session because (apart from knowing I've bookmarked some registered-only works) this is the exact same error I get when trying to run the following code on a registered-only work
    workid = AO3.utils.workid_from_url(url)
    work = AO3.Work(workid)
  2. I see the get_bookmarks() method does not accept a session argument and neither do _load_bookmarks() and get_work_from_banner()
  3. You may or may not see a pull request from me solving this exact issue. No promises, but I'm tempted