Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » scratchclient - A scratch API wrapper for python
- AdamKRPS425
-
Scratcher
44 posts
scratchclient - A scratch API wrapper for python
hi could, i have help for something, I made a python script to change a cloud variable but for some reason it never changes and gets stuck on the line
connection.set_cloud_variable("preset name", preset value)
- CoolCrafter1231
-
Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
So i tryed runing this script…
But it keeps giving me this error
I'm not sure on what do do or how to fix it
from scratchclient import ScratchSession, ScratchExceptions import getpass import json import os loginloop = True while loginloop: try: os.system("cls") print("VarMesh V1") username = input("Username: ") password = getpass.getpass("Password: ") session = ScratchSession(username, password) loginloop = False except ScratchExceptions.InvalidCredentialsException: os.system("cls") print("Username or passowrd is invalid") input() loginloop = True session.get_user("Coolcrafter1231").post_comment("Test")
But it keeps giving me this error
Traceback (most recent call last):
File "C:\Users\user\OneDrive\Desktop\vartest.py", line 21, in <module>
session.get_user("Coolcrafter1231").post_comment("Test")
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\scratchclient\User.py", line 103, in post_comment
raise UnauthorizedException("You are not allowed to do that")
scratchclient.ScratchExceptions.UnauthorizedException: You are not allowed to do that
Last edited by CoolCrafter1231 (Oct. 17, 2022 22:30:56)
- mrcoat
-
Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
So i tryed runing this script… But it keeps giving me this error.
I'm not entirely sure but it might be because your not allowed to post comments with bots.
- AdamKRPS425
-
Scratcher
44 posts
scratchclient - A scratch API wrapper for python
Hi I get this error
When running
Username and Password are both variables
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-4-9e12ee99e832> in <module> 1 from scratchclient import ScratchSession ----> 2 session = ScratchSession(Username, Password) 2 frames /usr/local/lib/python3.7/dist-packages/requests/structures.py in __getitem__(self, key) 52 53 def __getitem__(self, key): ---> 54 return self._store[key.lower()][1] 55 56 def __delitem__(self, key): KeyError: 'set-cookie'
When running
from scratchclient import ScratchSession
session = ScratchSession(Username, Password)
Username and Password are both variables
- JackK211424
-
Scratcher
500+ posts
scratchclient - A scratch API wrapper for python
Hi I get this error
Is your username and password correct? I cant think of any reason why that would throw an error besides that.
- AdamKRPS425
-
Scratcher
44 posts
scratchclient - A scratch API wrapper for python
Hi, for some reason connecting to a project is taking infinitely long for me, wondering if this is a common issue or..that happens to me too I don't know why
edit: king of the page hahaaha
- AdamKRPS425
-
Scratcher
44 posts
scratchclient - A scratch API wrapper for python
Hi I get this error
When running
Username and Password are both variables
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-4-9e12ee99e832> in <module> 1 from scratchclient import ScratchSession ----> 2 session = ScratchSession(Username, Password) 2 frames /usr/local/lib/python3.7/dist-packages/requests/structures.py in __getitem__(self, key) 52 53 def __getitem__(self, key): ---> 54 return self._store[key.lower()][1] 55 56 def __delitem__(self, key): KeyError: 'set-cookie'
When running
from scratchclient import ScratchSession
session = ScratchSession(Username, Password)
Username and Password are both variables
- AdamKRPS425
-
Scratcher
44 posts
scratchclient - A scratch API wrapper for python
what does the error mean?Hi I get this error
Is your username and password correct? I cant think of any reason why that would throw an error besides that.
everything is correct
Last edited by AdamKRPS425 (Nov. 16, 2022 02:08:25)
- scratcher2286
-
Scratcher
79 posts
scratchclient - A scratch API wrapper for python
Super great that I can make a bot with this!
- Knightbot63
-
Scratcher
1000+ posts
scratchclient - A scratch API wrapper for python
hi could, i have help for something, I made a python script to change a cloud variable but for some reason it never changes and gets stuck on the lineWas the cloud variable name exactly? Because I don't think it detects case-sensitive things.connection.set_cloud_variable("preset name", preset value)
- AntonLikesPotato
-
Scratcher
4 posts
scratchclient - A scratch API wrapper for python
Is there a decode or encode command? Or do i need to use other libraries like scratchattach or code it myself?
- simy8
-
Scratcher
13 posts
scratchclient - A scratch API wrapper for python
Im having trouble installing the scratchclient. I've tried both the pip and the shell methods. When I try installing using the shell it prints “1” Also Im windows if that helps
My browser / operating system: Windows NT 10.0, Chrome 110.0.0.0, No Flash version detected
My browser / operating system: Windows NT 10.0, Chrome 110.0.0.0, No Flash version detected
Last edited by simy8 (Feb. 17, 2023 22:26:45)
- mrcoat
-
Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
(#615)Do you mean command prompt? That's what I usually use for pip. Also I remember having a problem about not having C# installed from Visual studio, or something like that.
Im having trouble installing the scratchclient. I've tried both the pip and the shell methods. When I try installing using the shell it prints “1” Also Im windows if that helps
My browser / operating system: Windows NT 10.0, Chrome 110.0.0.0, No Flash version detected
- WojtekGame
-
Scratcher
1000+ posts
scratchclient - A scratch API wrapper for python
is anyone willing to help me write docs? there's a lot of stuff I need to document and help would be appreciatedsure
- Collin_The_Newmaker
-
Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
Hi! Probably it was discussed already, but it's a mess going through the entire thread.
When I get value of a cloud variable in a project using “connection.get_cloud_variable(name)” it works fine a few times, but it then raises the CloudVariableException: Variable is not in this project. (The variable is actually there lol). Are there fixes or workarounds?
When I get value of a cloud variable in a project using “connection.get_cloud_variable(name)” it works fine a few times, but it then raises the CloudVariableException: Variable is not in this project. (The variable is actually there lol). Are there fixes or workarounds?
Last edited by Collin_The_Newmaker (March 10, 2023 18:39:48)
- SuperGame592_Remade
-
Scratcher
9 posts
scratchclient - A scratch API wrapper for python
A few days ago I noticed there was no easy way to mess with scratch's API in Python so I created a python module to do this. https://pypi.org/project/scratchclient/
You can install it usingpip install scratchclient
Thanks to this npm package for the reference code and ilcheese2 for their modified version of my cloud code.
You can report issues on the (email removed by moderator - please don't share contact information) this topic, or my scratch profile.
Usage:
Basic usage:Cloud connection:from scratchclient import ScratchSession session = ScratchSession("ceebee", "--uwu--") # post comments session.get_user("Paddle2See").post_comment("OwO") # lots of other stuff print(session.get_project(450216269).get_comments()[0].content) print(session.get_studio(29251822).description)from scratchclient import ScratchSession session = ScratchSession("griffpatch", "SecurePassword7") connection = session.create_cloud_connection(450216269) connection.set_cloud_variable("variable name", 5000) @connection.on("set") def on_set(variable): print(variable.name, variable.value) print(connection.get_cloud_variable("other variable"))
I havent made documentation yet because I'm lazyso feel free to ask questions in this topic.
Can this be added for other languages? On second thought maybe not as people get more access to the API then if you use python. You decide? I'm too lazy to. —_w_—
if <[(me)] = [good]> then
reply
end
Last edited by SuperGame592_Remade (March 30, 2023 17:42:45)
- BlueNoodle29
-
Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
I noticed that with some scratch projects, attempting to establish a cloud connection yields an infinite waiting cycle. Any idea why this may be?
Last edited by BlueNoodle29 (May 14, 2023 02:26:05)
- AdamKRPS425
-
Scratcher
44 posts
scratchclient - A scratch API wrapper for python
I noticed that with some scratch projects, attempting to establish a cloud connection yields an infinite waiting cycle. Any idea why this may be?This happens to me - EVERY TIME its very annoying, someone please help with this
- nikoniko0826
-
Scratcher
16 posts
scratchclient - A scratch API wrapper for python
Please tell me the code to attach stars and hearts to Project.
- StevoSure
-
Scratcher
3 posts
scratchclient - A scratch API wrapper for python
can anyone tell me the thing that is wrong here?
import requests
import time
from scratchclient import ScratchSession
def get_project_views(project_id):
url = f"https://api.scratch.mit.edu/projects/{project_id}“
response = requests.get(url)
if response.status_code == 200:
data = response.json()
views = data.get(”stats“, {}).get(”views“, ”Not available“)
return views
else:
print(f”Failed to fetch data. Status code: {response.status_code}“)
return None
def update_cloud_variable(scratch, variable_name, value):
try:
scratch.set_cloud_variable(variable_name, value)
print(f”Successfully updated {variable_name} to {value}“)
except Exception as e:
print(f”Failed to update {variable_name}. Error: {e}“)
scratch = ScratchSession()
project_id = 970959964
while True:
views = get_project_views(project_id)
if views is not None:
update_cloud_variable(scratch, ”views“, views)
time.sleep(60) # Wait for 60 seconds before sending the next update
else:
print(”Failed to retrieve views.")
break
import requests
import time
from scratchclient import ScratchSession
def get_project_views(project_id):
url = f"https://api.scratch.mit.edu/projects/{project_id}“
response = requests.get(url)
if response.status_code == 200:
data = response.json()
views = data.get(”stats“, {}).get(”views“, ”Not available“)
return views
else:
print(f”Failed to fetch data. Status code: {response.status_code}“)
return None
def update_cloud_variable(scratch, variable_name, value):
try:
scratch.set_cloud_variable(variable_name, value)
print(f”Successfully updated {variable_name} to {value}“)
except Exception as e:
print(f”Failed to update {variable_name}. Error: {e}“)
scratch = ScratchSession()
project_id = 970959964
while True:
views = get_project_views(project_id)
if views is not None:
update_cloud_variable(scratch, ”views“, views)
time.sleep(60) # Wait for 60 seconds before sending the next update
else:
print(”Failed to retrieve views.")
break
- Discussion Forums
- » Advanced Topics
-
» scratchclient - A scratch API wrapper for python











so feel free to ask questions in this topic.

