Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » scratchattach - A Scratch API wrapper (Python)
- Blackout32
- Scratcher
500+ posts
scratchattach - A Scratch API wrapper (Python)
Could you share your entire script? Why doesn't this work?
if username in players:
print(“Exist”)
else:
print(“Not Exist”)
players is a list.
username is a string of someone's username.
- TimMcCool
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
Appel and sends them back to this project, I made it first in PyCharm Community and it worked perfectly, I would get this output: (Pls read the entire post)Help I made a code that gets the latest 5 comments inThe output after the direction is the comments at that time of course lol but on replit I get an Attribute Error:/Users/Josh/.conda/envs/ScratchTest/bin/python /Users/Josh/Desktop/ScratchTest/Comment_Test.py
bug that needs like a hide block that i am gonna fix. by @Corazon22scratch
You are smarter than me! by @TimurYYppgTATStudios
Pretty cool game Griffpatch! by @TimurYYppgTATStudios
Process finished with exit code 0And I'm not sure what to do about it because I don't get any error when logging in or anything, here's my code:Traceback (most recent call last):
File "main.py", line 9, in <module>
comments = project.comments(limit=40, offset=0)
AttributeError: 'NoneType' object has no attribute 'comments'Also some other things:#Ignore all of the comment prints I used those to try and figure out what was going on import scratchattach as scratch3 from scratchattach import Encoding import os #Only for replit session = scratch3.login("Joshisaurio_test", "Password XD I used an environment variable in replit like this: os.environ['Password'] (I already know that I have to set them on the menu on the left)") conn = session.connect_cloud(project_id="705289873") #print(type(conn)) project = session.connect_project("60917032") #print(type(project)) comments = project.comments(limit=40, offset=0) #print(type(comments)) #print(comments) content1 = comments[0] content1 = content1[0] content1 = content1["content"] user1 = comments[0] user1 = user1[0] user1 = user1["author"] user1 = user1["username"] visibility1 = comments[0] #print(type(visibility1)) visibility1 = visibility1[0] #print(type(visibility1)) visibility1 = visibility1["visibility"] #print(type(visibility1)) #print(visibility1) print(f"{content1} by @{user1}") content2 = comments[0] content2 = content2[1] content2 = content2["content"] user2 = comments[0] user2 = user2[1] user2 = user2["author"] user2 = user2["username"] visibility2 = comments[0] visibility2 = visibility2[1] visibility2 = visibility2["visibility"] print(f"{content2} by @{user2}") content3 = comments[0] content3 = content3[2] content3 = content3["content"] user3 = comments[0] user3 = user3[2] user3 = user3["author"] user3 = user3["username"] visibility3 = comments[0] visibility3 = visibility3[2] visibility3 = visibility3["visibility"] print(f"{content3} by @{user3}") if visibility1 == "visible": conn.set_var("User1", Encoding.encode(user1)) else: conn.set_var("User1", Encoding.encode("[Deleted comment]")) if visibility2 == "visible": conn.set_var("User2", Encoding.encode(user2)) else: conn.set_var("User2", Encoding.encode("[Deleted comment]")) if visibility3 == "visible": conn.set_var("User3", Encoding.encode(user3)) else: conn.set_var("User3", Encoding.encode("[Deleted comment]")) if visibility1 == "visible": conn.set_var("Text1", Encoding.encode(content1)) else: conn.set_var("Text1", Encoding.encode("[Deleted comment]")) if visibility2 == "visible": conn.set_var("Text2", Encoding.encode(content2)) else: conn.set_var("Text2", Encoding.encode("[Deleted comment]")) if visibility3 == "visible": conn.set_var("Text3", Encoding.encode(content3)) else: conn.set_var("Text3", Encoding.encode("[Deleted comment]"))
1.- I tried to get the comments like this:but I would only get an empty list… it only worked with the 40 limit.comments = project.comments(limit=3, offset=0)
2.- I already know about the banned replit IP so I tried logging in like this:I tried to get the SessionID with this code:#The session id is invented XD session = scratch3.Session("379ehdjkvga49tuq4837iufh", username="Joshisaurio_test")And filled in the sessionID spot with it, but it didn't work…#This works perfectly print(session.session_id)
It gives me this error:And I think you removed the advanced login with xtoken and sessionID from the documentation since I can't find it…Warning: Logged in, but couldn't fetch XToken. Cloud variables will still work, but other features may not work properly.
If you're using an online IDE (like replit.com) Scratch possibly banned its IP adress.
Traceback (most recent call last):
File "/Users/Josh/Desktop/ScratchTest/Comment_Test.py", line 9, in <module>
project = session.connect_project("60917032")
File "/Users/Josh/.conda/envs/ScratchTest/lib/python3.8/site-packages/scratchattach/_session.py", line 255, in connect_project
if not project.update():
File "/Users/Josh/.conda/envs/ScratchTest/lib/python3.8/site-packages/scratchattach/_project.py", line 126, in update
"x-token": self._session.xtoken,
AttributeError: 'Session' object has no attribute 'xtoken'
This has been quite weird, lately… ScratchConnect also isn't working on replit with sessionID and everything…
I won't be able to host my project ig T_T I don't have any working libraries now…
To log in with sessionID and xtoken, do this:
import scratchattach as scratch3 session = scratch3.Session("sessionid", username="username") session.xtoken = "xtoken" #sets the xtoken manually
Developer of scratchattach, the most popular Python Scratch API wrapper
- -Twirlblast-
- Scratcher
89 posts
scratchattach - A Scratch API wrapper (Python)
I'm just thinking, how about making a community on StackOverflow? It would be easier to answer code-related questions
- kccuber
- Scratcher
1000+ posts
scratchattach - A Scratch API wrapper (Python)
stackoverflow requires users to be of a certain age (probably 13, and that's your countries laws not some silly requirement that websites added), and i'm sure that's above scratch's requirement. I'm just thinking, how about making a community on StackOverflow? It would be easier to answer code-related questions
- BLUE_2030
- Scratcher
3 posts
scratchattach - A Scratch API wrapper (Python)
replit
Last edited by BLUE_2030 (June 27, 2022 03:10:36)
- ben-278
- Scratcher
15 posts
scratchattach - A Scratch API wrapper (Python)
can you teah me on replitOof the whole point of it was it to work on replit. Well idk I love that code so I'll keep it anyway… I'll try to find another way to host my serverNoBTW did you use it on replit???
- boomerangBS
- Scratcher
10 posts
scratchattach - A Scratch API wrapper (Python)
there is always written on the console “couldn't find Xtoken” so some functions don't work help me!
- kccuber
- Scratcher
1000+ posts
scratchattach - A Scratch API wrapper (Python)
there is always written on the console “couldn't find Xtoken” so some functions don't work help me!
don't use it on replit, it doesn't work there because some people were doing bad things on scratch using replit (like spamming) and the scratch team decided to block all requests from replit's ip addresses.
- MagicCrayon9342
- Scratcher
1000+ posts
scratchattach - A Scratch API wrapper (Python)
You can use replit right!? Enroll for a free domain at nic.eu.org and use it in replit?there is always written on the console “couldn't find Xtoken” so some functions don't work help me!
don't use it on replit, it doesn't work there because some people were doing bad things on scratch using replit (like spamming) and the scratch team decided to block all requests from replit's ip addresses.
- Joshisaurio
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
What's that?You can use replit right!? Enroll for a free domain at nic.eu.org and use it in replit?there is always written on the console “couldn't find Xtoken” so some functions don't work help me!
don't use it on replit, it doesn't work there because some people were doing bad things on scratch using replit (like spamming) and the scratch team decided to block all requests from replit's ip addresses.
- kccuber
- Scratcher
1000+ posts
scratchattach - A Scratch API wrapper (Python)
That doesn't change replit's IP address. You can use replit right!? Enroll for a free domain at nic.eu.org and use it in replit?
- Joshisaurio
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
I get this error:Thanks!~Snip~
To log in with sessionID and xtoken, do this:import scratchattach as scratch3 session = scratch3.Session("sessionid", username="username") session.xtoken = "xtoken" #sets the xtoken manually
Traceback (most recent call last):
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_cloud.py”, line 40, in _connect
self.websocket.connect(
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/websocket/_core.py”, line 248, in connect
self.handshake_response = handshake(self.sock, url, *addrs, **options)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/websocket/_handshake.py”, line 57, in handshake
status, resp = _get_resp_headers(sock)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/websocket/_handshake.py”, line 148, in _get_resp_headers
raise WebSocketBadStatusException(“Handshake status %d %s”, status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “main.py”, line 162, in <module>
conn = session.connect_cloud(project_id=“705289873”)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_session.py”, line 241, in connect_cloud
return _cloud.CloudConnection(username = self._username, session_id = self.session_id, project_id = int(project_id))
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_cloud.py”, line 17, in __init__
self._connect(cloud_host=cloud_host)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_cloud.py”, line 47, in _connect
raise(_exceptions.ConnectionError)
scratchattach._exceptions.ConnectionError
- ben-278
- Scratcher
15 posts
scratchattach - A Scratch API wrapper (Python)
I get this error:Thanks!~Snip~
To log in with sessionID and xtoken, do this:import scratchattach as scratch3 session = scratch3.Session("sessionid", username="username") session.xtoken = "xtoken" #sets the xtoken manually
Traceback (most recent call last):
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_cloud.py”, line 40, in _connect
self.websocket.connect(
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/websocket/_core.py”, line 248, in connect
self.handshake_response = handshake(self.sock, url, *addrs, **options)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/websocket/_handshake.py”, line 57, in handshake
status, resp = _get_resp_headers(sock)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/websocket/_handshake.py”, line 148, in _get_resp_headers
raise WebSocketBadStatusException(“Handshake status %d %s”, status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “main.py”, line 162, in <module>
conn = session.connect_cloud(project_id=“705289873”)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_session.py”, line 241, in connect_cloud
return _cloud.CloudConnection(username = self._username, session_id = self.session_id, project_id = int(project_id))
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_cloud.py”, line 17, in __init__
self._connect(cloud_host=cloud_host)
File “/home/runner/CommentViewServer/venv/lib/python3.8/site-packages/scratchattach/_cloud.py”, line 47, in _connect
raise(_exceptions.ConnectionError)
scratchattach._exceptions.ConnectionError
I do to
- AdelPekker
- Scratcher
5 posts
scratchattach - A Scratch API wrapper (Python)
um hi what is this i don't know python i just started JaVa
- Joshisaurio
- Scratcher
100+ posts
scratchattach - A Scratch API wrapper (Python)
An advanced text coding language (Like java), in this forum you can ask questions on how to use it and learn! um hi what is this i don't know python i just started JaVahttps://scratch.mit.edu/discuss/topic/614802/
- kccuber
- Scratcher
1000+ posts
scratchattach - A Scratch API wrapper (Python)
Maybe don't learn Java right now. (Unless you are talking about JavaScript, which is an entirely different programming language for the web that is probably going to be much easier than Java) Java isn't the easiest programming language, you should do JavaScript or Python before moving to Java. um hi what is this i don't know python i just started JaVa
- lalusangani
- Scratcher
21 posts
scratchattach - A Scratch API wrapper (Python)
when green flag clicked
ask [how 2 convert?] and wait