Discuss Scratch

mrcoat
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
javakid7171
Scratcher
26 posts

scratchclient - A scratch API wrapper for python

hi
Sid72020123
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

mrcoat wrote:

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
Will you use scratchconnect or scratch2py?
mrcoat
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

Sid72020123 wrote:

mrcoat wrote:

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
Will you use scratchconnect or scratch2py?
Not sure yet, I want to do a bit o research.
Sid72020123
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

mrcoat wrote:

Sid72020123 wrote:

mrcoat wrote:

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
Will you use scratchconnect or scratch2py?
Not sure yet, I want to do a bit o research.
Ok!
hubblefam
Scratcher
45 posts

scratchclient - A scratch API wrapper for python

so when i run the thing to change a cloud variable the program does not give me an error but it does not do anything.
the code:
from scratchclient import ScratchSession
session = ScratchSession(“Hubblefam”, “#########”)
connection = session.create_cloud_connection(596965016)
connection.set_cloud_variable(“CLOUD”, 1)
@connection.on(“set”)
def on_set(variable):
print(variable.name, variable.value)
print(connection.get_cloud_variable(“CLOUD”))
Goldtabby
Scratcher
95 posts

scratchclient - A scratch API wrapper for python

I am just going to make my own Scratch/Python API Module….
vikkcd
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

Goldtabby wrote:

I am just going to make my own Scratch/Python API Module….
Good luck.
Chiroyce
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

For @dhuls since they asked here

# after logging in and connecting to project
@connection.on("set")
def on_set(variable):
    print(f'{variable.name} has been set to {variable.value}')
    # variable.name is the name of the variable that was changed
    # variable.value is the value the variable was set to

Last edited by Chiroyce (Nov. 10, 2021 06:22:51)

Goldtabby
Scratcher
95 posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

Goldtabby wrote:

I am just going to make my own Scratch/Python API Module….
Good luck.
Not that heard, I already started
nini2009ph
Scratcher
87 posts

scratchclient - A scratch API wrapper for python

Data = session.get_user(“nini2009ph”).get_followers()
for i in Data:
print(i.username)
session.get_studio(30610675).invite_curator(i.username)


error: self.owner = data KeyError: ‘owner’

Last edited by nini2009ph (Nov. 12, 2021 17:21:54)

nini2009ph
Scratcher
87 posts

scratchclient - A scratch API wrapper for python

nini2009ph wrote:

Data = session.get_user(“nini2009ph”).get_followers()
for i in Data:
print(i.username)
session.get_studio(30610675).invite_curator(i.username)


error: self.owner = data KeyError: ‘owner’
i did something in the scratch client code and now it works
Shawn12344
Scratcher
5 posts

scratchclient - A scratch API wrapper for python

Hello can i get some help with an error i keep getting. the error i get is websocket._exceptions.websocketconnectionclosedexception: connection to remote host was lost. i get the error after my code has been running for about 10+ hours.
JackK211424
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

Shawn12344 wrote:

Hello can i get some help with an error i keep getting. the error i get is websocket._exceptions.websocketconnectionclosedexception: connection to remote host was lost. i get the error after my code has been running for about 10+ hours.
I'm pretty sure that scratch closes the cloud connection after a time. The only way to fix this would be to use the Try: Except: anytime you use a request and if you get an error then reconnect.
vikkcd
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.

Last edited by vikkcd (Nov. 14, 2021 15:11:58)

ajsya
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.
You might need to share the project…
vikkcd
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

ajsya wrote:

vikkcd wrote:

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.
You might need to share the project…
sure
-EmeraldThunder-
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

I've been making a pfp loader and have stumbled across a problem. The connection times out and gives me an error I would normally like to catch this error using a try statement and restart the main function although I am only using one function tied to the @connection.on('set') decorator. How can I catch a timeout and cause a restart.
@connection.on('set')
def main(variable):
    if variable.name[2:] == "Request":
        print(f'Received: {variable.value}')
        pfp = requests.get(f'https://api.scratch.mit.edu/users/{decode(variable.value)[0]}/').json()['profile']['images']['60x60']
        image = Image.open(requests.get(pfp, stream=True).raw)
        width, height = image.size
        values = list(image.getdata())
        send(values, width, height)
        connection.set_cloud_variable('Serving', int(connection.get_cloud_variable('Serving')) + 1)
ajsya
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

-EmeraldThunder- wrote:

I've been making a pfp loader and have stumbled across a problem. The connection times out and gives me an error I would normally like to catch this error using a try statement and restart the main function although I am only using one function tied to the @connection.on('set') decorator. How can I catch a timeout and cause a restart.
@connection.on('set')
def main(variable):
    if variable.name[2:] == "Request":
        print(f'Received: {variable.value}')
        pfp = requests.get(f'https://api.scratch.mit.edu/users/{decode(variable.value)[0]}/').json()['profile']['images']['60x60']
        image = Image.open(requests.get(pfp, stream=True).raw)
        width, height = image.size
        values = list(image.getdata())
        send(values, width, height)
        connection.set_cloud_variable('Serving', int(connection.get_cloud_variable('Serving')) + 1)
wouldn't you do:
try:
  #your function
except TimeoutError:
  #do function again or whatever else here
should be something like that

Last edited by ajsya (Nov. 14, 2021 16:15:03)

Sid72020123
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

ajsya wrote:

vikkcd wrote:

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.
You might need to share the project…
sure
Yes! The project needs to be shared.

Powered by DjangoBB