Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » scratchattach - A Scratch API wrapper (Python)
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Please help! I've been trying to figure this out for 2 days Thanks, that fixed it but the Scratch servers can't seem to keep up while I'm updating the cloud variables via return and then my variable with 11k characters of data. Which line of code would slow down the return speed?
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:
Here is the error I get almost immediately when the code receives a request:
Just to clarify, this error doesn't happen when thread=False in the request decorator. Has anyone ran into this before? Thanks!
Here is a simplified version of my code:
import scratchattach as scratch3
import os
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:
Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Just to clarify, this error doesn't happen when thread=False in the request decorator. Has anyone ran into this before? Thanks!
Last edited by Dinosu (July 27, 2023 20:26:22)
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
I'm in CodeSandbox (https://codesandbox.io ), with Scratchattach v1.2.7.Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!

Last edited by Dinosu (July 27, 2023 20:30:52)
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Resolved?Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!
client.run(thread=True) instead of just client.run() I'll try it but I was just reading though the docs to make sure I didn't miss anything.
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
It didn't work, but thanks for helping anywayResolved?Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!
client.run(thread=True) instead of just client.run() I'll try it but I was just reading though the docs to make sure I didn't miss anything.

- MonkeyBean2
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
import os
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Just to clarify, this error doesn't happen when thread=False in the request decorator. Has anyone ran into this before? Thanks!
I'm not particularly familiar with scratchattatch's code, but it seems as though _cloud_requests.py line 440 might get executed before the code that's ran in the thread on line 431 is finished, thus erroring as the outputs list isn't populated yet… maybe… But as I said, I'm not that familiar with the code, so this might be complete and utter nonsense.
https://github.com/TimMcCool/scratchattach/blob/main/scratchattach/_cloud_requests.py#L440
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
Yeah, that sounds right. Maybe it has to do with the fact that my requests take a little while to process.My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
import os
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Just to clarify, this error doesn't happen when thread=False in the request decorator. Has anyone ran into this before? Thanks!
I'm not particularly familiar with scratchattatch's code, but it seems as though _cloud_requests.py line 440 might get executed before the code that's ran in the thread on line 431 is finished, thus erroring as the outputs list isn't populated yet… maybe… But as I said, I'm not that familiar with the code, so this might be complete and utter nonsense.
https://github.com/TimMcCool/scratchattach/blob/main/scratchattach/_cloud_requests.py#L440
- catninja7878
-
4 posts
scratchattach - A Scratch API wrapper (Python)
notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
It would be very nice if you stopped, there is no place for you in here, Ninja. notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
- MonkeyBean2
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Yeah. It seems like there's a race condition going on here - Both threads are trying to do stuff to the same variable at the same time.Yeah, that sounds right. Maybe it has to do with the fact that my requests take a little while to process.My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
import os
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Just to clarify, this error doesn't happen when thread=False in the request decorator. Has anyone ran into this before? Thanks!
I'm not particularly familiar with scratchattatch's code, but it seems as though _cloud_requests.py line 440 might get executed before the code that's ran in the thread on line 431 is finished, thus erroring as the outputs list isn't populated yet… maybe… But as I said, I'm not that familiar with the code, so this might be complete and utter nonsense.
https://github.com/TimMcCool/scratchattach/blob/main/scratchattach/_cloud_requests.py#L440
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
That's very interesting and odd at the same time…Yeah. It seems like there's a race condition going on here - Both threads are trying to do stuff to the same variable at the same time.Yeah, that sounds right. Maybe it has to do with the fact that my requests take a little while to process.My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
import os
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Just to clarify, this error doesn't happen when thread=False in the request decorator. Has anyone ran into this before? Thanks!
I'm not particularly familiar with scratchattatch's code, but it seems as though _cloud_requests.py line 440 might get executed before the code that's ran in the thread on line 431 is finished, thus erroring as the outputs list isn't populated yet… maybe… But as I said, I'm not that familiar with the code, so this might be complete and utter nonsense.
https://github.com/TimMcCool/scratchattach/blob/main/scratchattach/_cloud_requests.py#L440
- MonkeyBean2
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
*there's no place for those comments in here, Ninja.It would be very nice if you stopped, there is no place for you in here, Ninja. notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Fair point. I stand corrected!*there's no place for those comments in here, Ninja.It would be very nice if you stopped, there is no place for you in here, Ninja. notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
It didn't work, but thanks for helping anywayYou know what, the request still returns despite the error, so I'll just set up a forbidden try/except pass lol
Nevermind, I guess that cancels some important function beyond line 440 that returns data from the request. This solution doesn't work.
- MonkeyBean2
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
It didn't work, but thanks for helping anywayYou know what, the request still returns despite the error, so I'll just set up a forbidden try/except pass lol
Nevermind, I guess that cancels some important function beyond line 440 that returns data from the request. This solution doesn't work.
If you mean "some important function that responds to the request", then yes, self._parse_output (which, by the way, is badly named, as it does more than just parse the output) will not be called, which in turn won't call self._respond.
- ScratchTheCoder12345
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Hey! I just installed VSCode after using PyCharm and Replit for a while and ran into an issue…
This is my code!
import scratchattach as scratch3
session = scratch3.login(“ScratchTheCoder12345”, )
e = session.get_message_count()
print(e)
This is my output in the console.
File "/Users//Desktop/VSCode/Scratchattach.py", line 3, in <module>
e = session.get_message_count()
AttributeError: ‘Session’ object has no attribute ‘get_message_count’
Thanks for the help!
In the end, I'd like to get the message count via the session.
This is my code!
import scratchattach as scratch3
session = scratch3.login(“ScratchTheCoder12345”, )
e = session.get_message_count()
print(e)
This is my output in the console.
File "/Users//Desktop/VSCode/Scratchattach.py", line 3, in <module>
e = session.get_message_count()
AttributeError: ‘Session’ object has no attribute ‘get_message_count’
Thanks for the help!

In the end, I'd like to get the message count via the session.
Last edited by ScratchTheCoder12345 (July 27, 2023 21:00:37)
- Dinosu
-
82 posts
scratchattach - A Scratch API wrapper (Python)
Oh! This works when I delete the thread=True in the decorators. Thank you!Resolved?Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.Didn't you forget to import os? My Scratchattach script is working fine until I set some requests to run in threads.
Here is a simplified version of my code:import scratchattach as scratch3
session = scratch3.Session(os.environ.get('sid'), username='Dinosu')
connection = session.connect_cloud(os.environ.get('project_id'))
client = scratch3.CloudRequests(connection)
@client.request(thread=True)
def ping():
return 'pong'
client.run()
Here is the error I get almost immediately when the code receives a request:Traceback (most recent call last):
File "/workspace/main.py", line 61, in <module>
client.run()
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 269, in run
self._run(events, data_from_websocket=data_from_websocket)
File "/usr/local/lib/python3.11/site-packages/scratchattach/_cloud_requests.py", line 440, in _run
output = self.outputs[request_id]["output"]
~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '274240'
Has anyone ran into this before? Thanks!
client.run(thread=True) instead of just client.run() I'll try it but I was just reading though the docs to make sure I didn't miss anything.