Open apple502j opened 6 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.
@towerofnix That didn't work either. I got [{'username': '', 'num_tries': 0, 'success': 0, 'msg': '', 'messages': [], 'id': None}]
@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}]'
@Kenny2github hm, I can guess one stupid thing: Requests doesn't automaticlly add Cookie header
I'm not so sure, let me test without explicit Cookie
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).
@towerofnix the problem here is that apparently the Python Requests library doesn't send cookies with Session requests like it should.
I got it working. Will be released on April after finding what made POST/PUT unable to do.
April came and went... forgot to close? BTW do u know any profile comment API ?
I wanted to add this kind of things, but it seems not working...