Discuss Scratch

-Twirlblast-
Scratcher
69 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

Ellirio2 wrote:

How do you start programming for Scratch in Python like what dpes TImMcCool do and what do you lot use
git clone scratchattach into your directory and then run npm or chocolatey to build it and run

Yeah
-FreeEngines-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

-Twirlblast- wrote:

Ellirio2 wrote:

How do you start programming for Scratch in Python like what dpes TImMcCool do and what do you lot use
git clone scratchattach into your directory and then run npm or chocolatey to build it and run

Yeah
.. or just pip install scratchattach
Blackout32
Scratcher
500+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

infintyrussia wrote:

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.
Could you share your entire script?
TimMcCool
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

Joshisaurio wrote:

Help I made a code that gets the latest 5 comments in 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)
/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 0
The output after the direction is the comments at that time of course lol but on replit I get an Attribute Error:
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'
And 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:
#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]"))
Also some other things:
1.- I tried to get the comments like this:
comments = project.comments(limit=3, offset=0)
but I would only get an empty list… it only worked with the 40 limit.

2.- I already know about the banned replit IP so I tried logging in like this:
#The session id is invented XD
session = scratch3.Session("379ehdjkvga49tuq4837iufh", username="Joshisaurio_test")
I tried to get the SessionID with this code:
#This works perfectly
print(session.session_id)
And filled in the sessionID spot with it, but it didn't work…
It gives me this error:
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'
And I think you removed the advanced login with xtoken and sessionID from the documentation since I can't find it…
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

My profile / Mein Profil: @TimMcCool
-Twirlblast-
Scratcher
69 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (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 for cloud interactions and more! (Python)

-Twirlblast- wrote:

I'm just thinking, how about making a community on StackOverflow? It would be easier to answer code-related questions
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.


Made using Nord Theme & Inkscape
BLUE_2030
Scratcher
3 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

replit

Last edited by BLUE_2030 (June 27, 2022 03:10:36)

-Twirlblast-
Scratcher
69 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

BLUE_2030 wrote:

replit
glitch.me
ben-278
Scratcher
3 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

Joshisaurio wrote:

KROKOBIL wrote:

Joshisaurio wrote:

KROKOBIL wrote:

BTW did you use it on replit???
No
Oof 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 server
can you teah me on replit
boomerangBS
Scratcher
10 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (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 for cloud interactions and more! (Python)

boomerangBS wrote:

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.


Made using Nord Theme & Inkscape
MagicCrayon9342
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

kccuber wrote:

boomerangBS wrote:

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.
You can use replit right!? Enroll for a free domain at nic.eu.org and use it in replit?

no more useless information in my signature, instead a little fun fact.

this fact is not fun.
Joshisaurio
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

TimMcCool wrote:

Joshisaurio wrote:

~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
Thanks!


Banner by @NFlex23


Banner by @NFlex23

Joshisaurio
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

MagicCrayon9342 wrote:

kccuber wrote:

boomerangBS wrote:

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.
You can use replit right!? Enroll for a free domain at nic.eu.org and use it in replit?
What's that?


Banner by @NFlex23


Banner by @NFlex23

kccuber
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

MagicCrayon9342 wrote:

You can use replit right!? Enroll for a free domain at nic.eu.org and use it in replit?
That doesn't change replit's IP address.


Made using Nord Theme & Inkscape
Joshisaurio
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

Joshisaurio wrote:

TimMcCool wrote:

Joshisaurio wrote:

~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
Thanks!
I get this error:

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


Banner by @NFlex23


Banner by @NFlex23

infintyrussia
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

If you use a session id to log in can it be rejected if your network is blocked? And does it expire because in chrome it says it expires for me.


ben-278
Scratcher
3 posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

Joshisaurio wrote:

Joshisaurio wrote:

TimMcCool wrote:

Joshisaurio wrote:

~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
Thanks!
I get this error:

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 for cloud interactions and more! (Python)

um hi what is this i don't know python i just started JaVa
Joshisaurio
Scratcher
100+ posts

scratchattach - A Scratch API wrapper for cloud interactions and more! (Python)

AdelPekker wrote:

um hi what is this i don't know python i just started JaVa
An advanced text coding language (Like java), in this forum you can ask questions on how to use it and learn! https://scratch.mit.edu/discuss/topic/614802/


Banner by @NFlex23


Banner by @NFlex23

Powered by DjangoBB

Standard | Mobile