Commit c31661d6 authored by minamotorin's avatar minamotorin Committed by GitHub

Merge branch 'master' into twintproject/twint#1335

parents 1e028e78 e643a479
## Updates from twintproject/twint
### twint.token.RefreshTokenException: Could not find the Guest token in HTML
This problem doesn't happen recently.
#### Related
- [twintproject/twint#1320](https://github.com/twintproject/twint/issues/1320)
- [twintproject/twint#1322](https://github.com/twintproject/twint/pull/1322)
- [twintproject/twint#1328](https://github.com/twintproject/twint/pull/1328)
- [twintproject/twint#1061](https://github.com/twintproject/twint/issues/1061)
- [twintproject/twint#1114](https://github.com/twintproject/twint/issues/1114)
### json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The fix is **not complete**.
......
......@@ -65,5 +65,30 @@ class Token:
logme.debug('Found guest token in HTML')
self.config.Guest_token = str(match.group(1))
else:
self.config.Guest_token = None
raise RefreshTokenException('Could not find the Guest token in HTML')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
'authority': 'api.twitter.com',
'content-length': '0',
'authorization': self.config.Bearer_token,
'x-twitter-client-language': 'en',
'x-csrf-token': res.cookies.get("ct0"),
'x-twitter-active-user': 'yes',
'content-type': 'application/x-www-form-urlencoded',
'accept': '*/*',
'sec-gpc': '1',
'origin': 'https://twitter.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://twitter.com/',
'accept-language': 'en-US',
}
self._session.headers.update(headers)
req = self._session.prepare_request(requests.Request('POST', 'https://api.twitter.com/1.1/guest/activate.json'))
res = self._session.send(req, allow_redirects=True, timeout=self._timeout)
if 'guest_token' in res.json():
logme.debug('Found guest token in JSON')
self.config.Guest_token = res.json()['guest_token']
else:
self.config.Guest_token = None
raise RefreshTokenException('Could not find the Guest token in HTML')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment