我试图在REPLIT (python)上使用划痕客户端模块,但是当我试图运行这段代码时,它会给出一个随机错误:
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'发布于 2022-08-22 17:01:11
在scratchclient的文档中,我找到了页面Replit的使用和以下文本
"Scratch blocks most requests from the Replit, so you must work around it."编辑:
文件全文:
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.https://stackoverflow.com/questions/73438787
复制相似问题