twintproject / twint

An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.
MIT License
15.85k stars 2.73k forks source link

[ERROR] twint.token.RefreshTokenException: Could not find the Guest token in HTML #1433

Open michaelmoreno opened 1 year ago

michaelmoreno commented 1 year ago

Attempting to run a trivial user search

import twint

c = twint.Config()
c.Username = "elonmusk"
c.User_full = True
c.Store_object = True
c.Hide_output = True
twint.run.Lookup(c)

Raising Exception Could not find the Guest token in HTML

Traceback (most recent call last):
  File "/Users/michaelmoreno/proj/twitter-api/src/main.py", line 20, in <module>
    twint.run.Lookup(c)
  File "/Users/michaelmoreno/proj/twitter-api/venv/src/twint/twint/run.py", line 386, in Lookup
    run(config)
  File "/Users/michaelmoreno/proj/twitter-api/venv/src/twint/twint/run.py", line 329, in run
    get_event_loop().run_until_complete(Twint(config).main(callback))
                                        ^^^^^^^^^^^^^
  File "/Users/michaelmoreno/proj/twitter-api/venv/src/twint/twint/run.py", line 36, in __init__
    self.token.refresh()
  File "/Users/michaelmoreno/proj/twitter-api/venv/src/twint/twint/token.py", line 69, in refresh
    raise RefreshTokenException('Could not find the Guest token in HTML')
twint.token.RefreshTokenException: Could not find the Guest token in HTML

Python Version: 3.11 pip version: 23.0.1 twint version: 2.1.21 OS: MacOS Montery 12.6 (M2)

I have tried installing twint both through pip install twint and pip install --upgrade -e git+https://github.com/twintproject/twint.git@origin/master#egg=twint

Output of pip list

aiodns             3.0.0
aiohttp            3.8.4
aiohttp-socks      0.8.0
aiosignal          1.3.1
async-timeout      4.0.2
attrs              22.2.0
beautifulsoup4     4.11.2
bs4                0.0.1
cchardet           2.1.7
certifi            2022.12.7
cffi               1.15.1
charset-normalizer 3.0.1
Cython             0.29.33
dataclasses        0.6
elastic-transport  8.4.0
elasticsearch      8.6.2
fake-useragent     1.1.1
frozenlist         1.3.3
geographiclib      2.0
geopy              2.3.0
googletransx       2.4.2
idna               3.4
multidict          6.0.4
numpy              1.24.2
pandas             1.5.3
pip                23.0.1
pycares            4.3.0
pycparser          2.21
PySocks            1.7.1
python-dateutil    2.8.2
python-socks       2.1.1
pytz               2022.7.1
requests           2.28.2
schedule           1.1.0
setuptools         67.4.0
six                1.16.0
soupsieve          2.4
twint              2.1.21    /Users/michaelmoreno/proj/twitter-api/venv/src/twint
urllib3            1.26.14
yarl               1.8.2
726232111 commented 1 year ago

https://github.com/twintproject/twint/issues/1061#issuecomment-1010716112

After replacing the token.py file, twint can work normally

adrianfant commented 1 year ago

I have the same issue:

RefreshTokenException: Could not find the Guest token in HTML

adrianfant commented 1 year ago

Has the issue been resolved?

dehueck commented 1 year ago

also have this error: twint.token.RefreshTokenException: Could not find the Guest token in HTML

dehueck commented 1 year ago

replacing token.py with what? thanks

726232111 commented 1 year ago
  1. install twint (need install git) , dont't use pip install twint command. pip3 install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint

  2. get file path python.exe -c "import twint;print(twint.__file__);"

  3. replace token.py file https://gist.github.com/moxak/ed83dd4169112a0b1669500fe855101a

dehueck commented 1 year ago

wow ok many thanks. sorry tired & missed your link to the comment there.

maharani032 commented 1 year ago

does it work? because from 28 feb 2023 it always return Raising Exception Could not find the Guest token in HTML

dehueck commented 1 year ago

it appears to be working, yes. had to change token.py file.

maharani032 commented 1 year ago

I still having error

      RefreshTokenException                     Traceback (most recent call last)
      ~\AppData\Local\Temp\ipykernel_8280\828474447.py in <module>
            4 c.Pandas=True
            5 c.Lang = "id"
      ----> 6 twint.run.Search(c)

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in Search(config, callback)
          408     config.Followers = False
          409     config.Profile = False
      --> 410     run(config, callback)
          411     if config.Pandas_au:
          412         storage.panda._autoget("tweet")

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in run(config, callback)
          327         raise
          328 
      --> 329     get_event_loop().run_until_complete(Twint(config).main(callback))
          330 
          331 

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in __init__(self, config)
           34         # USAGE : to get a new guest token simply do `self.token.refresh()`
           35         self.token = token.Token(config)
      ---> 36         self.token.refresh()
           37         self.conn = db.Conn(config.Database)
           38         self.d = datelock.Set(self.config.Until, self.config.Since)

      ~\AppData\Roaming\Python\Python39\site-packages\twint\token.py in refresh(self)
           67         else:
           68             self.config.Guest_token = None
      ---> 69             raise RefreshTokenException('Could not find the Guest token in HTML')

      RefreshTokenException: Could not find the Guest token in HTML
lolujubril commented 1 year ago

I am having the same issue and I have tried replacing token.py

726232111 commented 1 year ago

I use python3.8.8, I don't know if it will help you

dehueck commented 1 year ago

I still having error

      RefreshTokenException                     Traceback (most recent call last)
      ~\AppData\Local\Temp\ipykernel_8280\828474447.py in <module>
            4 c.Pandas=True
            5 c.Lang = "id"
      ----> 6 twint.run.Search(c)

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in Search(config, callback)
          408     config.Followers = False
          409     config.Profile = False
      --> 410     run(config, callback)
          411     if config.Pandas_au:
          412         storage.panda._autoget("tweet")

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in run(config, callback)
          327         raise
          328 
      --> 329     get_event_loop().run_until_complete(Twint(config).main(callback))
          330 
          331 

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in __init__(self, config)
           34         # USAGE : to get a new guest token simply do `self.token.refresh()`
           35         self.token = token.Token(config)
      ---> 36         self.token.refresh()
           37         self.conn = db.Conn(config.Database)
           38         self.d = datelock.Set(self.config.Until, self.config.Since)

      ~\AppData\Roaming\Python\Python39\site-packages\twint\token.py in refresh(self)
           67         else:
           68             self.config.Guest_token = None
      ---> 69             raise RefreshTokenException('Could not find the Guest token in HTML')

      RefreshTokenException: Could not find the Guest token in HTML

what does your environment setup look like? When I was working with this issue in development I changed the token.py file that was in /venv folder in my project...had to do something else for production

726232111 commented 1 year ago

I still having error

      RefreshTokenException                     Traceback (most recent call last)
      ~\AppData\Local\Temp\ipykernel_8280\828474447.py in <module>
            4 c.Pandas=True
            5 c.Lang = "id"
      ----> 6 twint.run.Search(c)

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in Search(config, callback)
          408     config.Followers = False
          409     config.Profile = False
      --> 410     run(config, callback)
          411     if config.Pandas_au:
          412         storage.panda._autoget("tweet")

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in run(config, callback)
          327         raise
          328 
      --> 329     get_event_loop().run_until_complete(Twint(config).main(callback))
          330 
          331 

      ~\AppData\Roaming\Python\Python39\site-packages\twint\run.py in __init__(self, config)
           34         # USAGE : to get a new guest token simply do `self.token.refresh()`
           35         self.token = token.Token(config)
      ---> 36         self.token.refresh()
           37         self.conn = db.Conn(config.Database)
           38         self.d = datelock.Set(self.config.Until, self.config.Since)

      ~\AppData\Roaming\Python\Python39\site-packages\twint\token.py in refresh(self)
           67         else:
           68             self.config.Guest_token = None
      ---> 69             raise RefreshTokenException('Could not find the Guest token in HTML')

      RefreshTokenException: Could not find the Guest token in HTML

what does your environment setup look like? When I was working with this issue in development I changed the token.py file that was in /venv folder in my project...had to do something else for production

Have you tried replacing the files in the '~\AppData\Roaming\Python\Python39\site-packages\twint\' directory?