Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » scratchattach - A Scratch API wrapper (Python)
- zaid1442011
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
Nevermind, it was just trubowarp refusing my connection or something.
- MonkeyBean2
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
Yeah, it seems like you simply can't get previous values of cloud variables in scratch without querying the cloud logs (and even then that won't always work).(#2683)After some troubleshooting, it seams that the problem is with the TwCloudConnection function. The .get_cloud() works with no issues. I even tried to do the same thing but use scratchcommunication to set the variables (It works, but not with Turbowarp's cloud server).
No offense, but this is not a great way to do this. It will spam turbowarp with unnecessary updates (unless scratchattach prevents changing a cloud variable that's already been changed, that could cause problems though). Plus, .get_cloud() is depreciated now, and does not work in the latest version of scratchattach, and even if you are using an older version that supports this I think you might need to connect to the scratch cloud server first.
You can update scratchattach to the latest version within your terminal.pip install scratchattach --upgrade
A better way to do this would be to open up the websocket connection to scratch yourself, and call .recv(), something like this: (untested, tell me if it doesn't work)#Import modules import scratchattach as scratch3 from dotenv import load_dotenv import os import time #To add rate limiter import websocket # websocket-client import json #Load the .env file(s) load_dotenv('app.env') #Set variables to the enviroment variables sessionID=os.getenv('sessionID') username=os.getenv('username') scratch_project=os.getenv('scratch_project') server=os.getenv('cloud_host') # Log into scratch session = scratch3.Session(sessionID, username=username) # Connect to scratch cloud server ws = websocket.WebSocket() ws.connect( "wss://clouddata.scratch.mit.edu", cookie="scratchsessionsid=" + session.session_id + ";", origin="https://scratch.mit.edu", enable_multithread=True ) # Connect to Turbowarp or another cloud server turbo_conn = scratch3.TwCloudConnection(project_id=scratch_project, username=username, cloud_host=server, purpose="A test for a bot that syncs Scratch variables to another cloud server", contact="zaid1442011 on scratch and [redacted]") while True: msgs = ws.recv().split('\n') for msg in msgs: if len(msg) == 0: continue parsed = json.loads(msg) if parsed['method'] == 'set': # Sets the variable in Turbowarp turbo_conn.set_var(parsed['name'][4:], parsed['value']) time.sleep(0.1) # Rate limiter (might not be needed)
(@TimMcCool, is there a better way of doing this? maybe cloud requests idk)
- TimMcCool
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
KEEP getting messages about this forum. Why is this?Okay, I That means you're following this discussion
:|move (100000000000000000000000000000000000000000000000000000) steps
- dynamicsofscratch
- Scratcher
1000+ posts
scratchattach - A Scratch API wrapper (Python)
(#2690)lolKEEP getting messages about this forum. Why is this?Okay, I That means you're following this discussion
:|move (100000000000000000000000000000000000000000000000000000) steps
- zaid1442011
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
Does Turbowarp's cloud server block connections from cloud bots or I forgot to add something?
- TimMcCool
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
In the past, many people reported they were unable to connect to Scratch's cloud variables because they got this error:
I was never able to reproduce the error - until I recently stumbled upon it myself on a new device. I found a way to fix it which will be implemented in scratchattach soon / in a future update.
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)
I was never able to reproduce the error - until I recently stumbled upon it myself on a new device. I found a way to fix it which will be implemented in scratchattach soon / in a future update.
- elip100
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
(#2692)This should work:
session.get_message_count() should definitely exist…(´・ω・`)session.get_message_count() ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Session' object has no attribute 'get_message_count'. Did you mean: 'message_count'?
session.get_linked_user().message_count()
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
- TimMcCool
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
putting client.run(no_packet_loss=True) might fix this Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
Last edited by TimMcCool (Aug. 5, 2024 03:22:55)
- zaid1442011
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
I found I suffered all of this time because the EU instance of Turbowarp's cloud server is down.
- Da-thing
- Scratcher
73 posts
scratchattach - A Scratch API wrapper (Python)
It's mostly just the Scratch API HTTP requests tied up into a package. how do you guys make that
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
login with 2 variables ex: Does anyone know how to use Scratchattach to log in and operate with multiple accounts?
session = scratch3.login(“username”, “password”)then latter use session or session2 depending on what account you want to use.
session2 = scratch3.login(“username2”, “password”)
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
do I place this at the bottom of the script replacing the client.run()?putting client.run(no_packet_loss=True) might fix this Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
- elip100
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
(#2704)Yes replace client.run() withdo I place this at the bottom of the script replacing the client.run()?putting client.run(no_packet_loss=True) might fix this Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
client.run(no_packet_loss=True)
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
okay thanks!(#2704)Yes replace client.run() withdo I place this at the bottom of the script replacing the client.run()?putting client.run(no_packet_loss=True) might fix this Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.client.run(no_packet_loss=True)
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
cool I would of never thought of that though I have never used .append soo i have no idea how you would use that.-snip
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
yeah same I keep getting xtoken errors or it just fails to log in I am getting so many login errors.
uhhhhhm…
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
I want to make my scratchattach project work on turbowarp where you can enter a password but i am not sure if it is possible to view/ decode the cloud data logs which would make it easy to find other peoples passwords.
- wvzack
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
what i mean was i wasent sure if it would be possible for people to see turbowarps data logs and then decode your passcodeI want to make my scratchattach project work on turbowarp where you can enter a password but i am not sure if it is possible to view/ decode the cloud data logs which would make it easy to find other peoples passwords.
conn = session.connect_tw_cloud(“project_id”)
value = scratch3.get_tw_var(“project_id”, “variable”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
variables = scratch3.get_tw_cloud(“project_id”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
- redspacecat
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
TurboWarp doesn't have accessible cloud logs and also you aren't putting your password in there. (Unless I'm misunderstanding)what i mean was i wasent sure if it would be possible for people to see turbowarps data logs and then decode your passcodeI want to make my scratchattach project work on turbowarp where you can enter a password but i am not sure if it is possible to view/ decode the cloud data logs which would make it easy to find other peoples passwords.
conn = session.connect_tw_cloud(“project_id”)
value = scratch3.get_tw_var(“project_id”, “variable”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
variables = scratch3.get_tw_cloud(“project_id”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)