scratchattach
scratchattach copied to clipboard
Favourite/Love gives KeyError: "userFavorite/userLove"
It feels like it randomly happens out of nowhere, I'm quite positive it's not a rate exceeding error, as when I do it manually it stays after reloading the page.
Error for debugging: "...\site-packages\scratchattach\project.py", line 370, in unfavorite if r['userFavorite'] is True: KeyError: 'userFavorite'"
How often does this error occur? Can you provide your code?
@TimMcCool It happens quite often, sometimes a project or two does actually unfavourite, here's the code:
def Write(input):
os.system('CLS')
print(input)
#sign-in
Write("Logging in...")
session = scratch3.login() #hidden for obvious reasons
MainUser = session.get_linked_user()
Write("Finding Projects...")
Projects = []
for i in range(math.ceil(MainUser.favorites_count() / 20)):
projects_chunk = MainUser.favorites(limit=20, offset=i * 20)
Projects += projects_chunk
for i in range(len(Projects)):
project = session.connect_project(Projects[i].id)
Write("Removing Project " + project.title)
project.unfavorite()
What I've noticed is that while you can unfavourite as many projects as you like manually, It takes a minute or two to actually update on your profile, and it the code breaks the same time it doesn't update manually. I'm pretty sure it might be the scratch API at fault here and not scratchattach 🥺
i fixed this in my private fork, here's how you can do it:
- open the %appdata%\Local\Programs\Python\Python310\lib\site-packages\scratchattach\project.py file
- go to line 373 (unlove)
-
change
if r["userLove"] is True:
toif r.get("userLove") == True:
- try it
- it it doesn't work, try adding a 1 second delay
v2.0 will raise the APIError Exception and show the server response when this happens