Sid72020123 / scratchconnect

Python Library to connect Scratch API and much more.
https://sid72020123.github.io/scratchconnect/
MIT License
26 stars 14 forks source link

Scratchconnect `set-cookie` Login Error #59

Closed GitbyteMaster closed 1 year ago

GitbyteMaster commented 1 year ago

I am simply trying to login with my Scratch account with this function. I'm working in Replit.

user = scratchconnect.ScratchConnect("g_bite_masters", ms) #'ms' is my password in an environment variable. 

Assigning the env. variable and importing os and scratchconnect are the only things in this script at the moment. When I run this code, however:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    user = scratchconnect.ScratchConnect("g_bite_masters", ms)
  File "/home/runner/SORA-Api/venv/lib/python3.10/site-packages/scratchconnect/ScratchConnect.py", line 44, in __init__
    self._login(cookie=False, auto_cookie_login=self.auto_cookie_login)
  File "/home/runner/SORA-Api/venv/lib/python3.10/site-packages/scratchconnect/ScratchConnect.py", line 96, in _login
    self.session_id = re.search('"(.*)"', request.headers["Set-Cookie"]).group()
  File "/home/runner/SORA-Api/venv/lib/python3.10/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'set-cookie'

This might just be a problem internally, but could you help out anyways?

Sid72020123 commented 1 year ago

Oh. If you are using replit, you need to use the Online IDE Login feature: https://github.com/Sid72020123/scratchconnect#using-scratchconnect-in-online-ides-like-replit

If you have any problems, ask me here! Steps to get session ID: https://sid72020123.github.io/scratchconnect/session_id/#steps-to-get-the-session-id

GitbyteMaster commented 1 year ago

Okay, thanks! I will check this out, and tell you if I find an error on my end.

Sid72020123 commented 1 year ago

Ok. If the issue is resolved you can close it anytime and we can still continue our communication here...

GitbyteMaster commented 1 year ago

Okay, I've decided to just use a desktop for this job instead. Now, connecting cloud variables isn't working. I'm using a MacBook Air if it helps.

Sid72020123 commented 1 year ago

Hm... Can you share the code here? Or is there any error message you get?

GitbyteMaster commented 1 year ago

Sorry for the delay! Here's my error:

Traceback (most recent call last):
  File "/Users/*/Desktop/*/Cloud Handler.py", line 5, in <module>
    variables = project.connect_cloud_variables()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scratchconnect/Project.py", line 504, in connect_cloud_variables
    return CloudConnection.CloudConnection(project_id=self.project_id, client_username=self.client_username,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scratchconnect/CloudConnection.py", line 55, in __init__
    self._make_connection()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scratchconnect/CloudConnection.py", line 124, in _make_connection
    self._ws = websocket.WebSocket(enable_multithread=True)
TypeError: WebSocket.__init__() got an unexpected keyword argument 'enable_multithread'
Sid72020123 commented 1 year ago

Oh. Then uninstall the library and install it again!

Try running this command: pip uninstall websocket && pip uninstall scratchconnect && pip uninstall websocket-client && pip install scratchconnect

If that gives an error then try running each command manually (the commands are separated by "&&")

GitbyteMaster commented 1 year ago

And now, on execution:

Traceback (most recent call last):
  File "~/Desktop/SORA/Cloud Handler.py", line 5, in <module>
    variables = project.connect_cloud_variables()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scratchconnect/Project.py", line 504, in connect_cloud_variables
    return CloudConnection.CloudConnection(project_id=self.project_id, client_username=self.client_username,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scratchconnect/CloudConnection.py", line 55, in __init__
    self._make_connection()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scratchconnect/CloudConnection.py", line 125, in _make_connection
    self._ws.connect(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websocket/_core.py", line 249, in connect
    self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websocket/_http.py", line 136, in connect
    sock = _ssl_socket(sock, options.sslopt, hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websocket/_http.py", line 271, in _ssl_socket
    sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websocket/_http.py", line 247, in _wrap_sni_socket
    return context.wrap_socket(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)
Sid72020123 commented 1 year ago

Oh looks like your computer's SSL certificates got old (or expired) or maybe IDK what's happening. I don't know much about certificates so, I can't help you. Sorry.

BTW you can also try to use TimMcCool's scratchattach and tell me if that library works on your device??

GitbyteMaster commented 1 year ago

It did, on a Windows. Sorry for being so late!

Sid72020123 commented 1 year ago

It's ok. No problem.

So, did ScratchAttach worked on your device??

Anyways I'm so busy these days that I don't get time to update this unused library. I recommend you to switch to ScratchAttach.