iSarabjitDhiman / TweeterPy

TweeterPy is a python library to extract data from Twitter. TweeterPy API lets you scrape data from a user's profile like username, userid, bio, followers/followings list, profile media, tweets, etc.
MIT License
164 stars 29 forks source link

Couldn't find guest token! #58

Closed datastd-dev closed 6 months ago

datastd-dev commented 6 months ago

Hi,

Code was working yesterday but I received error below today. Could someone help?

2024-05-17 08:54:35,974 [INFO] :: NumExpr defaulting to 8 threads.
2024-05-17 08:54:37,956 [ERROR] :: Couldn't find guest token
2024-05-17 08:54:37,957 [ERROR] :: Couldn't generate a new session.
Couldn't find guest token
Traceback (most recent call last):
  File ".....python3.11/site-packages/tweeterpy/tweeterpy.py", line 159, in generate_session
    Path.GUEST_TOKEN_URL, method="POST", session=self.session).get('guest_token', util.find_guest_token(home_page))
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".............python3.11/site-packages/tweeterpy/util.py", line 89, in find_guest_token
    raise Exception("Couldn't find guest token")
Exception: Couldn't find guest token
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[1], line 9
      5 import pandas as pd
      6 from tweeterpy import config
----> 9 twitter = TweeterPy()
     10 config.UPDATE_API = False

File ......./python3.11/site-packages/tweeterpy/tweeterpy.py:29, in TweeterPy.__init__(self)
     27     disable_external_only = config.DISABLE_EXTERNAL_LOGS if not config.DISABLE_LOGS else False
     28     set_log_level(logging.ERROR, external_only=disable_external_only)
---> 29 self.generate_session()
     30 # update api endpoints
     31 try:

File "...........python3.11/site-packages/tweeterpy/tweeterpy.py:159, in TweeterPy.generate_session(self, auth_token)
    156 self.session.headers.update(util.generate_headers())
    157 home_page = make_request(Path.BASE_URL, session=self.session)
    158 guest_token = make_request(
--> 159     Path.GUEST_TOKEN_URL, method="POST", session=self.session).get('guest_token', util.find_guest_token(home_page))
    160 self.session.headers.update({'X-Guest-Token': guest_token})
    161 self.session.cookies.update({'gt': guest_token})

File /opt/anaconda3/lib/python3.11/site-packages/tweeterpy/util.py:89, in find_guest_token(page_source)
     87 guest_token_match = re.search(guest_token_regex,str(page_source))
     88 if not guest_token_match:
---> 89     raise Exception("Couldn't find guest token")
     90 guest_token = guest_token_match.group(1)
     91 return guest_token

Exception: Couldn't find guest token
iSarabjitDhiman commented 6 months ago

Hey @datastd-dev are you using multiple threads?

datastd-dev commented 6 months ago

Hiç, Yes, i guess as default. I did not change.Sarabjit Dhiman @.***> şunları yazdı (17 May 2024 09:38): Hey @datastd-dev are you using multiple threads?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

iSarabjitDhiman commented 6 months ago

Ahh I see, twitter just redirected all the old twitter.com URLs to x.com image

Edit: Already fixed.

datastd-dev commented 6 months ago

I took same error although uninstalling and installing again. what should i do?

iSarabjitDhiman commented 6 months ago

@datastd-dev

run this command

pip install -U tweeterpy --no-cache-dir

Let me know how it goes

datastd-dev commented 6 months ago

solved. thanks a lot.

Sarabjit Dhiman @.***> şunları yazdı (17 May 2024 19:04):

@datastd-dev https://github.com/datastd-dev run this command

pip install -U tweeterpy Let me know how it goes

— Reply to this email directly, view it on GitHub https://github.com/iSarabjitDhiman/TweeterPy/issues/58#issuecomment-2117917551, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH2ISWTUJRM7FBSSIZIZWE3ZCYS7TAVCNFSM6AAAAABH3PTUD6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJXHEYTONJVGE. You are receiving this because you were mentioned.

New-dev0 commented 6 months ago

I am still getting this error

", line 162, in generate_session Path.GUEST_TOKEN_URL, method="POST", session=self.session).get('guest_token', util.find_guest_token(home_page)) File "_Python310\site-packages\tweeterpy\util.py", line 92, in find_guest_token raise Exception("Couldn't find guest token")
Exception: Couldn't find guest token

iSarabjitDhiman commented 6 months ago

I am still getting this error

", line 162, in generate_session Path.GUEST_TOKEN_URL, method="POST", session=self.session).get('guest_token', util.find_guest_token(home_page)) File "_Python310\site-packages\tweeterpy\util.py", line 92, in find_guest_token raise Exception("Couldn't find guest token")
Exception: Couldn't find guest token

Hey @New-dev0 Make sure to update the package


pip install -U tweeterpy --no-cache-dir