apple502j / scratchapi2

The New Scratch API Client.
https://pypi.org/project/scratchapi2/
GNU General Public License v3.0
17 stars 4 forks source link

Auth API! #10

Open apple502j opened 6 years ago

apple502j commented 6 years ago

I wanted to add this kind of things, but it seems not working...

towerofnix commented 5 years ago

Here is a reference I wrote recently (it's not published anywhere else yet): https://gist.github.com/towerofnix/cd5c0771446dc0ba81355fccc70ed1ea - It should be helpful for anyone implementing this.

apple502j commented 5 years ago

@towerofnix That didn't work either. I got [{'username': '', 'num_tries': 0, 'success': 0, 'msg': '', 'messages': [], 'id': None}]

Kenny2github commented 5 years ago

@apple502j Worked for me:

>>> r = s.post('https://scratch.mit.edu/accounts/login/', json={'username': 'TemplatesFTW', 'password': password, 'useMessages': True}, headers={'Cookie': 'scratchcsrftoken=' + s.cookies['scratchcsrftoken'], 'X-CSRFToken': s.cookies['scratchcsrftoken'], 'Referer': 'https://scratch.mit.edu', 'Origin': 'https://scratch.mit.edu', 'X-Requested-With': 'XMLHttpRequest'})
>>> len(r.text)
103
>>> r.text
'[{"username": "TemplatesFTW", "num_tries": 1, "success": 1, "msg": "", "messages": [], "id": 25341849}]'
apple502j commented 5 years ago

@Kenny2github hm, I can guess one stupid thing: Requests doesn't automaticlly add Cookie header

Kenny2github commented 5 years ago

I'm not so sure, let me test without explicit Cookie

towerofnix commented 5 years ago

In my JavaScript programs I have to explicitly specify/parse cookie and set-cookie as well - cookies are a browser concept that node-fetch doesn't know how to handle (even though the fetch defined in browser JS code does).

Kenny2github commented 5 years ago

@towerofnix the problem here is that apparently the Python Requests library doesn't send cookies with Session requests like it should.

apple502j commented 5 years ago

I got it working. Will be released on April after finding what made POST/PUT unable to do.

Quantum-Codes commented 3 years ago

April came and went... forgot to close? BTW do u know any profile comment API ?