Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anafvana opened this issue Apr 25, 2024 · 4 comments

Comments

@anafvana
Copy link

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)
  1. I see the get_bookmarks() method does not accept a session argument and neither do _load_bookmarks() and get_work_from_banner()
  2. You may or may not see a pull request from me solving this exact issue. No promises, but I'm tempted
@kc-frost
Copy link

kc-frost commented Nov 2, 2024

Were you able to find a workaround for this? I'm running into a similar issue.

@anafvana
Copy link
Author

anafvana commented Nov 2, 2024

Were you able to find a workaround for this? I'm running into a similar issue.

I haven’t really worked with this code in 5 months, so take this reply with a grain of salt.

Having said that, I remember I did continue trying a bit after posting this issue. This is a collection of my hazy memories:

  1. I realised I had some external bookmarks (from sites other than AO3). I think they might have been the reason for this? If I remember correctly, there was some difference in the HTML of the bookmark and I had suspicions that that’s where the problem lay.
  2. I vaguely remember that, while digging for the source of the issue, I found some uncaught exceptions? But I don’t remember if catching them after they’d propagated was enough.
  3. It’s very easy to hit AO3’s request limit, especially because when collecting data in bulk, you make A LOT of requests. Basically, you make as many requests as you would if clicking around to get the data. I remember my errors were often due to reaching the limit, and I think I tested using a VPN in-between runs of my script (and it worked). I also THINK I got an error that didn’t look like it was related to the request limit, but actually was (maybe it was this one? I’m sorry, I’m unsure).

I hope these give you at least something to start from!

@kc-frost
Copy link

kc-frost commented Nov 2, 2024

That does help somewhat. I've considered instead just getting the HTML of my bookmarks per page using BS4 and requests to work around the request limit (I unfortunately have too many bookmarks), then fiddling around with some of AO3's methods afterwards. For the external bookmarks and uncaught exceptions, I fortunately do not have the former as far as I remember, but I'll keep that in mind moving forward. Thank you!

@toiletbowlkuku
Copy link

The request limit is easily worked around by backing off for a few seconds when you encounter an error then retrying. Just write a wrapper to catch the HTTPError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants