Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

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

Open
michaelmoreno opened this issue Mar 3, 2023 · 14 comments

Comments

@michaelmoreno
Copy link

michaelmoreno commented Mar 3, 2023

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
Copy link

#1061 (comment)

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

@adrianfant
Copy link

I have the same issue:

RefreshTokenException: Could not find the Guest token in HTML

@adrianfant
Copy link

Has the issue been resolved?

@peterdh
Copy link

peterdh commented Mar 10, 2023

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

@peterdh
Copy link

peterdh commented Mar 10, 2023

replacing token.py with what? thanks

@726232111
Copy link

726232111 commented Mar 10, 2023

  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

@peterdh
Copy link

peterdh commented Mar 10, 2023

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

@maharani032
Copy link

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

@peterdh
Copy link

peterdh commented Mar 11, 2023

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

@maharani032
Copy link

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
Copy link

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

@726232111
Copy link

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

@peterdh
Copy link

peterdh commented Mar 14, 2023

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
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants