首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >KeyError:‘set-cookie’(Replit)

KeyError:‘set-cookie’(Replit)
EN

Stack Overflow用户
提问于 2022-08-21 22:59:39
回答 1查看 78关注 0票数 2

我试图在REPLIT (python)上使用划痕客户端模块,但是当我试图运行这段代码时,它会给出一个随机错误:

代码语言:javascript
复制
  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'
EN

回答 1

Stack Overflow用户

发布于 2022-08-22 17:01:11

scratchclient的文档中,我找到了页面Replit的使用和以下文本

代码语言:javascript
复制
"Scratch blocks most requests from the Replit, so you must work around it."

编辑:

文件全文:

代码语言:javascript
复制
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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73438787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档