2

I am trying to use the scratchclient module on REPLIT (python) but when i try to run this code it gives me this random error:

  Traceback (most recent call last):
     File "main.py", line 9, in <module>
    session = scratchclient.ScratchSession(username,     password)
  File "/home/runner/LumberingJuicyType/venv/lib/python3.8/site-packages/scratchclient/ScratchSession.py", line 31, in __init__
    self.login(password)
  File "/home/runner/LumberingJuicyType/venv/lib/python3.8/site-packages/scratchclient/ScratchSession.py", line 66, in login
    self.session_id = re.search('"(.*)"', request.headers["Set-Cookie"]).group()
  File "/home/runner/LumberingJuicyType/venv/lib/python3.8/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'set-cookie'
DybaTube
  • 21
  • 4
  • it seems it doesn't send cookie. Maybe you send wrong `username, password`. maybe you should run in `try/except` to catch error and to try with different `username, password` – furas Aug 21 '22 at 23:19
  • but its the correct one – DybaTube Aug 22 '22 at 16:34
  • not all request has to send header `set-cookie`. And it seems this request didn't use `set-cookie`. OR maybe server removed it for security reason. – furas Aug 22 '22 at 16:42
  • OR maybe page changed something in API and now module need modification. – furas Aug 22 '22 at 16:48
  • in documentation I found page [Usage on Replit](https://cubeythecube.github.io/scratchclient/replit/) and this text `"Scratch blocks most requests from the Replit, so you must work around it."` – furas Aug 22 '22 at 16:50

1 Answers1

0

In documentation for scratchclient I found page Usage on Replit and this text

"Scratch blocks most requests from the Replit, so you must work around it."

EDIT:

Full text from documentation:

Scratch blocks most requests from the Replit, so you must work around it. 
To log into Scratch, instead of using your password, you can use your token 
and session ID.

You can obtain your session ID by opening your browser developer tools, 
going to Application > Storage (or just Storage), then finding "scratchsessionsid" 
and copying the cookie value.

Getting the session ID from browser devtools

You can obtain your token by running this in your browser console:

    alert(
      document.getElementById('app')._reactRootContainer._internalRoot
      .current.child.pendingProps.store.getState()
      .session.session.user.token
    );

Then copying the value that flashes on your screen.

Then, to log in to scratchclient, use this code:

    from scratchclient import ScratchSession

    session = ScratchSession("username", session_id="session ID here", token="token here")

However, a lot of functionality still might not work. 
Sites like Glitch could serve your purpose in that case- 
or you can just host it on your own computer.
furas
  • 134,197
  • 12
  • 106
  • 148