Discuss Scratch

ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

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?
Please help! I've been trying to figure this out for 2 days
Dinosu
Scratcher
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:
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
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Dinosu wrote:

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!
Didn't you forget to import os?
Dinosu
Scratcher
82 posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

Dinosu wrote:

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!
Didn't you forget to import os?
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.
ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Dinosu wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

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!
Didn't you forget to import os?
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.
Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.
Dinosu
Scratcher
82 posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

Dinosu wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

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!
Didn't you forget to import os?
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.
Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.
I'm in CodeSandbox (https://codesandbox.io ), with Scratchattach v1.2.7.

Last edited by Dinosu (July 27, 2023 20:30:52)

ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

Dinosu wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

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!
Didn't you forget to import os?
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.
Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.
Resolved?


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
Scratcher
82 posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

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!
Didn't you forget to import os?
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.
Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.
Resolved?


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.
It didn't work, but thanks for helping anyway You know what, the request still returns despite the error, so I'll just set up a forbidden try/except pass lol
MonkeyBean2
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Dinosu wrote:

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
Scratcher
82 posts

scratchattach - A Scratch API wrapper (Python)

MonkeyBean2 wrote:

Dinosu wrote:

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
Yeah, that sounds right. Maybe it has to do with the fact that my requests take a little while to process.
catninja7878
Scratcher
4 posts

scratchattach - A Scratch API wrapper (Python)

notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

catninja7878 wrote:

notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
It would be very nice if you stopped, there is no place for you in here, Ninja.
MonkeyBean2
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Dinosu wrote:

MonkeyBean2 wrote:

Dinosu wrote:

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
Yeah, that sounds right. Maybe it has to do with the fact that my requests take a little while to process.
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.
ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

MonkeyBean2 wrote:

Dinosu wrote:

MonkeyBean2 wrote:

Dinosu wrote:

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
Yeah, that sounds right. Maybe it has to do with the fact that my requests take a little while to process.
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.
That's very interesting and odd at the same time…
MonkeyBean2
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

catninja7878 wrote:

notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
It would be very nice if you stopped, there is no place for you in here, Ninja.
*there's no place for those comments in here, Ninja.
ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

MonkeyBean2 wrote:

ScratchTheCoder12345 wrote:

catninja7878 wrote:

notifications notifications notifications notifications notifications notifications notifications notifications notifications notifications
It would be very nice if you stopped, there is no place for you in here, Ninja.
*there's no place for those comments in here, Ninja.
Fair point. I stand corrected!
Dinosu
Scratcher
82 posts

scratchattach - A Scratch API wrapper (Python)

Dinosu wrote:

It didn't work, but thanks for helping anyway You 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
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Dinosu wrote:

Dinosu wrote:

It didn't work, but thanks for helping anyway You 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
Scratcher
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.

Last edited by ScratchTheCoder12345 (July 27, 2023 21:00:37)

Dinosu
Scratcher
82 posts

scratchattach - A Scratch API wrapper (Python)

ScratchTheCoder12345 wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

ScratchTheCoder12345 wrote:

Dinosu wrote:

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!
Didn't you forget to import os?
I just forgot to write that in the simplified version. The error is related to scratchattach, not undefined modules.
Alright, just thinking. I've never seen that error before. What version are you on? I'll try recreating it.
Resolved?


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.
Oh! This works when I delete the thread=True in the decorators. Thank you!

Powered by DjangoBB