Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » scratchclient - A scratch API wrapper for python
- Dinosu
- Scratcher
76 posts
scratchclient - A scratch API wrapper for python
Hi, Raihan! I left a comment on your profile the other day (https://scratch.mit.edu/users/Raihan142857/#comments-157843985) about a problem I was having with scratchclient. I have been using Google Colab for scratchclient for a month or so, but only this week I was having the problem that scratchclient.ScratchSession('Dinosu', ‘<my password>’).create_cloud_connection(565436202) was not loading. I saw this question was already asked here, but I didn't see a response. I tried running this single line for two hours, and it didn't load, but this is the traceback I got when I did a keyboard interrupt:
—————————————————————————
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-eba3ae30fb2c> in <module>()
—-> 1 connection = session.create_cloud_connection(565436202)
14 frames
/usr/local/lib/python3.7/dist-packages/scratchclient/ScratchSession.py in create_cloud_connection(self, project_id)
138
139 def create_cloud_connection(self, project_id):
–> 140 return CloudConnection(project_id, self)
141
142 def explore_projects(self, mode=“trending”, query=“*”):
/usr/local/lib/python3.7/dist-packages/scratchclient/CloudConnection.py in __init__(self, project_id, client)
18 EventEmitter.__init__(self)
19 self._client = client
—> 20 self.connect(project_id)
21
22 def _send_packet(self, packet):
/usr/local/lib/python3.7/dist-packages/scratchclient/CloudConnection.py in connect(self, project_id)
43 )
44 self.emit(“handshake”)
—> 45 response = self._ws.recv().split(“\n”)
46 for variable in response:
47 try:
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv(self)
352 “”“
353 with self.readlock:
–> 354 opcode, data = self.recv_data()
355 if opcode == ABNF.OPCODE_TEXT:
356 return data.decode(”utf-8“)
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv_data(self, control_frame)
375 tuple of operation code and string(byte array) value.
376 ”“”
–> 377 opcode, frame = self.recv_data_frame(control_frame)
378 return opcode, frame.data
379
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv_data_frame(self, control_frame)
394 “”“
395 while True:
–> 396 frame = self.recv_frame()
397 if (isEnabledForTrace()):
398 trace(”++Rcv raw: “ + repr(frame.format()))
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv_frame(self)
433 self.frame_buffer.recv_frame(): ABNF frame object
434 ”“”
–> 435 return self.frame_buffer.recv_frame()
436
437 def send_close(self, status=STATUS_NORMAL, reason=bytes('', encoding='utf-8')):
/usr/local/lib/python3.7/dist-packages/websocket/_abnf.py in recv_frame(self)
335 # Header
336 if self.has_received_header():
–> 337 self.recv_header()
338 (fin, rsv1, rsv2, rsv3, opcode, has_mask, _) = self.header
339
/usr/local/lib/python3.7/dist-packages/websocket/_abnf.py in recv_header(self)
291
292 def recv_header(self):
–> 293 header = self.recv_strict(2)
294 b1 = header
295 fin = b1 >> 7 & 1
/usr/local/lib/python3.7/dist-packages/websocket/_abnf.py in recv_strict(self, bufsize)
370 # buffers allocated and then shrunk, which results in
371 # fragmentation.
–> 372 bytes_ = self.recv(min(16384, shortage))
373 self.recv_buffer.append(bytes_)
374 shortage -= len(bytes_)
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in _recv(self, bufsize)
517 def _recv(self, bufsize):
518 try:
–> 519 return recv(self.sock, bufsize)
520 except WebSocketConnectionClosedException:
521 if self.sock:
/usr/local/lib/python3.7/dist-packages/websocket/_socket.py in recv(sock, bufsize)
111 bytes_ = sock.recv(bufsize)
112 else:
–> 113 bytes_ = _recv()
114 except socket.timeout as e:
115 message = extract_err_message(e)
/usr/local/lib/python3.7/dist-packages/websocket/_socket.py in _recv()
88 def _recv():
89 try:
—> 90 return sock.recv(bufsize)
91 except SSLWantReadError:
92 pass
/usr/lib/python3.7/ssl.py in recv(self, buflen, flags)
1054 “non-zero flags not allowed in calls to recv() on %s” %
1055 self.__class__)
-> 1056 return self.read(buflen)
1057 else:
1058 return super().recv(buflen, flags)
/usr/lib/python3.7/ssl.py in read(self, len, buffer)
929 return self._sslobj.read(len, buffer)
930 else:
–> 931 return self._sslobj.read(len)
932 except SSLError as x:
933 if x.args == SSL_ERROR_EOF and self.suppress_ragged_eofs:
KeyboardInterrupt:
Do you know why this generally happens? Thank you in advance!
—————————————————————————
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-eba3ae30fb2c> in <module>()
—-> 1 connection = session.create_cloud_connection(565436202)
14 frames
/usr/local/lib/python3.7/dist-packages/scratchclient/ScratchSession.py in create_cloud_connection(self, project_id)
138
139 def create_cloud_connection(self, project_id):
–> 140 return CloudConnection(project_id, self)
141
142 def explore_projects(self, mode=“trending”, query=“*”):
/usr/local/lib/python3.7/dist-packages/scratchclient/CloudConnection.py in __init__(self, project_id, client)
18 EventEmitter.__init__(self)
19 self._client = client
—> 20 self.connect(project_id)
21
22 def _send_packet(self, packet):
/usr/local/lib/python3.7/dist-packages/scratchclient/CloudConnection.py in connect(self, project_id)
43 )
44 self.emit(“handshake”)
—> 45 response = self._ws.recv().split(“\n”)
46 for variable in response:
47 try:
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv(self)
352 “”“
353 with self.readlock:
–> 354 opcode, data = self.recv_data()
355 if opcode == ABNF.OPCODE_TEXT:
356 return data.decode(”utf-8“)
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv_data(self, control_frame)
375 tuple of operation code and string(byte array) value.
376 ”“”
–> 377 opcode, frame = self.recv_data_frame(control_frame)
378 return opcode, frame.data
379
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv_data_frame(self, control_frame)
394 “”“
395 while True:
–> 396 frame = self.recv_frame()
397 if (isEnabledForTrace()):
398 trace(”++Rcv raw: “ + repr(frame.format()))
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in recv_frame(self)
433 self.frame_buffer.recv_frame(): ABNF frame object
434 ”“”
–> 435 return self.frame_buffer.recv_frame()
436
437 def send_close(self, status=STATUS_NORMAL, reason=bytes('', encoding='utf-8')):
/usr/local/lib/python3.7/dist-packages/websocket/_abnf.py in recv_frame(self)
335 # Header
336 if self.has_received_header():
–> 337 self.recv_header()
338 (fin, rsv1, rsv2, rsv3, opcode, has_mask, _) = self.header
339
/usr/local/lib/python3.7/dist-packages/websocket/_abnf.py in recv_header(self)
291
292 def recv_header(self):
–> 293 header = self.recv_strict(2)
294 b1 = header
295 fin = b1 >> 7 & 1
/usr/local/lib/python3.7/dist-packages/websocket/_abnf.py in recv_strict(self, bufsize)
370 # buffers allocated and then shrunk, which results in
371 # fragmentation.
–> 372 bytes_ = self.recv(min(16384, shortage))
373 self.recv_buffer.append(bytes_)
374 shortage -= len(bytes_)
/usr/local/lib/python3.7/dist-packages/websocket/_core.py in _recv(self, bufsize)
517 def _recv(self, bufsize):
518 try:
–> 519 return recv(self.sock, bufsize)
520 except WebSocketConnectionClosedException:
521 if self.sock:
/usr/local/lib/python3.7/dist-packages/websocket/_socket.py in recv(sock, bufsize)
111 bytes_ = sock.recv(bufsize)
112 else:
–> 113 bytes_ = _recv()
114 except socket.timeout as e:
115 message = extract_err_message(e)
/usr/local/lib/python3.7/dist-packages/websocket/_socket.py in _recv()
88 def _recv():
89 try:
—> 90 return sock.recv(bufsize)
91 except SSLWantReadError:
92 pass
/usr/lib/python3.7/ssl.py in recv(self, buflen, flags)
1054 “non-zero flags not allowed in calls to recv() on %s” %
1055 self.__class__)
-> 1056 return self.read(buflen)
1057 else:
1058 return super().recv(buflen, flags)
/usr/lib/python3.7/ssl.py in read(self, len, buffer)
929 return self._sslobj.read(len, buffer)
930 else:
–> 931 return self._sslobj.read(len)
932 except SSLError as x:
933 if x.args == SSL_ERROR_EOF and self.suppress_ragged_eofs:
KeyboardInterrupt:
Do you know why this generally happens? Thank you in advance!
- JackK211424
- Scratcher
500+ posts
scratchclient - A scratch API wrapper for python
It could be possible, but the entire internet protocol would have to be changed.Nothing is impossible Let me re-phrase that. They cant do anything about it.
- Raihan142857
- Scratcher
1000+ posts
scratchclient - A scratch API wrapper for python
probably related to Do you know why this generally happens? Thank you in advance!https://scratch.mit.edu/discuss/post/5358270/
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- Goldtabby
- Scratcher
93 posts
scratchclient - A scratch API wrapper for python
something went wrong with the request, but not in a way that scratchclient knows how to handle. I’ve never looked the format of this sort of request, so I don’t know why this happens, but you could try checking if your password was correct.Ya… no the pass is perfect.
when green flag clickedThis is my Site! Check it out!
say [I make good quality projects!]
think [most of the time...]
say [come check them out!]
This is my profile! Come follow me!
Wireframe ship pro here: https://scratch.mit.edu/projects/369638452/
- silvxrcat
- Scratcher
500+ posts
scratchclient - A scratch API wrapper for python
hey there, can someone help me check my code before i run it? i want the server to run clean without bugs. here's a link to the repl. thanks!
- silvxrcat
- Scratcher
500+ posts
scratchclient - A scratch API wrapper for python
hey got scratchencoder error can someone please help?
Traceback (most recent call last):
File "main.py", line 50, in <module>
get = [receive("send"), match(receive("send")), db.keys()]
File "main.py", line 22, in receive
return Encoder.decode(temp2)
TypeError: decode() missing 1 required positional argument: 'text'
- Chiroyce
- Scratcher
1000+ posts
scratchclient - A scratch API wrapper for python
Inside the brackets put the encoded text to be decoded, like this hey got scratchencoder error can someone please help?
decode("020405201348285728348") # or even pass a a variable into it like this encoded = "020405201348285728348" decode(encoded)
It means that decode takes one argument called text TypeError: decode() missing 1 required positional argument: ‘text’
here's a link to the repl. thanks!Do you have any environment variables in that repl? Then anyone can see it as it's an invite to EDIT the repl and not a place to check the code hey there, can someone help me check my code before i run it? i want the server to run clean without bugs.
Last edited by Chiroyce (Sept. 2, 2021 02:57:59)
April Fools' topics:
— New Buildings in Scratch's headquarters
— Give every Scratcher an M1 MacBook Air
— Scratch should let users edit other Scratchers' projects
— Make a statue for Jeffalo
— Scratch Tech Tips™
— Make a Chiroyce statue emoji
<img src=“x” onerror=“alert('XSS vulnerability discovered')”>
this is a test sentence
- ajsya_test
- Scratcher
28 posts
scratchclient - A scratch API wrapper for python
Is it possible to view studio comments using this?
If so, how?
Edit:
I decided that this wasn't possible with scratchclient and after creating an issue in the Github repo someone told me about another module where this is possible but I decided to just use the requests module instead.
If so, how?
Edit:
I decided that this wasn't possible with scratchclient and after creating an issue in the Github repo someone told me about another module where this is possible but I decided to just use the requests module instead.
Last edited by ajsya_test (Sept. 16, 2021 02:44:12)
(Not edited by a moderator - Don't impersonate a moderator by adding this since a moderator didn't moderate to add this moderation in.)
Congratulations! You found an alt-account of @ajsya!
- Maclator
- Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
how do I check loves favorites and remixes?
PLEASE PLEASE PLEASE PLEASE LOOK AT THE COMMENTS OF THIS PROJECT
^^^just remember, the server is offline most of the time so don't expect it to work 100% of the time^^^
owner of wonows os (not working on it too much anymore) https://scratch.mit.edu/studios/30519993/
for collaboration, my time zone is central US time
and I am a part of:
PenHD (kind of)
BlueList (new topic, not too active in it anymore)
say [I'm happy!]
- fugimii
- Scratcher
21 posts
scratchclient - A scratch API wrapper for python
What I Did To View Comments Was I Used The Requests Module In Python And Used The Api Made By Scratch Here: https://en.scratch-wiki.info/wiki/Scratch_API
If You See A TurboWarp Autoplay Link Like This One Its Probably Important And You Should Click It
- ajsya
- Scratcher
1000+ posts
scratchclient - A scratch API wrapper for python
Here's an easy way to do it using scratchclient: how do I check loves favorites and remixes?
from scratchclient import ScratchSession session = ScratchSession("password", "username") # replace with your scratch account's password and username project = "1581299" # Put the project's ID that you want to lookup # Getting the counts and setting them to variables to make the easy to work with project_loves = session.get_project(project).love_count project_favorites = session.get_project(project).favorite_count project_remixes = session.get_project(project).remix_count # Just showing you the data print("Project {0} has: {1} loves, {2} favorites, and {3} remixes.".format(project, project_loves, project_favorites, project_remixes))
- Maclator
- Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
I got an error…Here's an easy way to do it using scratchclient: how do I check loves favorites and remixes?import snip
session = os.environ is just the session
from scratchclient import ScratchSession import os session = os.environ['session'] connection = "579010075" project_loves = session.get_project(project).love_count project_favorites = session.get_project(project).favorite_count project_remixes = session.get_project(project).remix_count connection.set_cloud_variable("heart", project_loves) connection.set_cloud_variable("star", project_favorites) connection.set_cloud_variable("remix", project_remixes)
and error
Traceback (most recent call last):
File "main.py", in line 5, in <module>
project_loves = session.get_project(project).love_count
AttributeError: 'str' object has no attribute 'get_project'
edit: if it is on scratches side https://scratch.mit.edu/projects/579010075/
Last edited by Maclator (Oct. 5, 2021 02:28:34)
PLEASE PLEASE PLEASE PLEASE LOOK AT THE COMMENTS OF THIS PROJECT
^^^just remember, the server is offline most of the time so don't expect it to work 100% of the time^^^
owner of wonows os (not working on it too much anymore) https://scratch.mit.edu/studios/30519993/
for collaboration, my time zone is central US time
and I am a part of:
PenHD (kind of)
BlueList (new topic, not too active in it anymore)
say [I'm happy!]
- Maclator
- Scratcher
100+ posts
scratchclient - A scratch API wrapper for python
I figured out the error! thanks for helping!I got an error…Here's an easy way to do it using scratchclient: how do I check loves favorites and remixes?import snip
session = os.environ is just the sessionimport snip
and errorTraceback (most recent call last):
snip
edit: if it is on scratch's side https://scratch.mit.edu/projects/579010075/
Last edited by Maclator (Oct. 5, 2021 02:38:02)
PLEASE PLEASE PLEASE PLEASE LOOK AT THE COMMENTS OF THIS PROJECT
^^^just remember, the server is offline most of the time so don't expect it to work 100% of the time^^^
owner of wonows os (not working on it too much anymore) https://scratch.mit.edu/studios/30519993/
for collaboration, my time zone is central US time
and I am a part of:
PenHD (kind of)
BlueList (new topic, not too active in it anymore)
say [I'm happy!]
- JackK211424
- Scratcher
500+ posts
scratchclient - A scratch API wrapper for python
import snip
I like that one given we are using python
- nini2009ph
- Scratcher
87 posts
scratchclient - A scratch API wrapper for python
I'm geting all followers of a user but i get realy weird objects and idk how to turn them in to usernames pls help me
- ahmetlii
- Scratcher
500+ posts
scratchclient - A scratch API wrapper for python
Would you mind sharing your code? I would help better if I would see the code. My best guess is either you didn't parse the output or you have passed it to an object instead of an array, which will of course result with JSON objects. I'm geting all followers of a user but i get realy weird objects and idk how to turn them in to usernames pls help me
- nini2009ph
- Scratcher
87 posts
scratchclient - A scratch API wrapper for python
data = session.get_user(“FREEZING_BLAZER”).get_followers(all=False)Would you mind sharing your code? I would help better if I would see the code. My best guess is either you didn't parse the output or you have passed it to an object instead of an array, which will of course result with JSON objects. I'm geting all followers of a user but i get realy weird objects and idk how to turn them in to usernames pls help me
- nini2009ph
- Scratcher
87 posts
scratchclient - A scratch API wrapper for python
and i get:Would you mind sharing your code? I would help better if I would see the code. My best guess is either you didn't parse the output or you have passed it to an object instead of an array, which will of course result with JSON objects. I'm geting all followers of a user but i get realy weird objects and idk how to turn them in to usernames pls help me
- nini2009ph
- Scratcher
87 posts
scratchclient - A scratch API wrapper for python
<scratchclient.User.User object at 0x000001B34B1AD730>