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 #1061

Open
weslleylira opened this issue Dec 7, 2020 · 51 comments

Comments

@weslleylira
Copy link

Issue Template

Error: twint.token.RefreshTokenException: Could not find the Guest token in HTML

Initial Check

If the issue is a request please specify that it is a request in the title (Example: [REQUEST] more features). If this is a question regarding 'twint' please specify that it's a question in the title (Example: [QUESTION] What is x?). Please only submit issues related to 'twint'. Thanks.

Make sure you've checked the following:

  • [] Python version is 3.6;
  • [] Updated Twint with pip3 install --user --upgrade -e git+https://github.com/twintproject/twint.git@origin/master#egg=twint;
  • [] I have searched the issues and there are no duplicates of this issue/question/request.

Command Ran

Please provide the exact command ran including the username/search/code so I may reproduce the issue.

Description of Issue

when running Twint I get the following error:
raceback (most recent call last):

File "twitter.py", line 18, in
twint.run.Search(c)
File "/home/ssm-user/.local/lib/python3.8/site-packages/twint/run.py", line 410, in Search
run(config, callback)
File "/home/ssm-user/.local/lib/python3.8/site-packages/twint/run.py", line 329, in run
get_event_loop().run_until_complete(Twint(config).main(callback))
File "/home/ssm-user/.local/lib/python3.8/site-packages/twint/run.py", line 36, in init
self.token.refresh()
File "/home/ssm-user/.local/lib/python3.8/site-packages/twint/token.py", line 68, in refresh
raise RefreshTokenException('Could not find the Guest token in HTML')
twint.token.RefreshTokenException: Could not find the Guest token in HTML

Environment Details

Using Ubuntu Server

@himanshudabas
Copy link
Contributor

this seems to me a duplicate of #957

@aburak256
Copy link

I have a similar issue. I am trying to collect some data with twint for time series analysis. To make that, I send searches hour by hour starting from january 2014. After 1000 search I get the same error.

I am using Colab
[] Updated Twint with pip3 install --user --upgrade -e git+https://github.com/twintproject/twint.git@origin/master#egg=twint;

@BonfaceKilz
Copy link

Getting the same error. Anyone able to come with a work-around?

@orestislampridis
Copy link

Is there a general problem with Twint currently? I seem to get the same error.

@theshouryagupta
Copy link

I am having the same issue right now. It was working fine 2 hours ago.

@BonfaceKilz
Copy link

I speculate there's yet another internal change within twitter that we aren't aware of...

@theshouryagupta
Copy link

Yeah @BonfaceKilz could be a possibility. Which os were you using ? I encountered this on Ubuntu 20.04.01 LTS.

@BonfaceKilz
Copy link

@theshouryagupta I'm running ArchLinux; though I've been running twint in a Guix[0] container

[0] https://github.com/pjotrp/guix-notes/blob/master/CONTAINERS.org

@orestislampridis
Copy link

I am using Windows 10. I don't think this is an os related problem.

@data-z
Copy link

data-z commented Dec 16, 2020

I am getting the same error. It was working fine last night. The I tried to clone the branch form above -himanshudabas commented 9 days ago
this seems to me a duplicate of #957 and am getting a different error

@theshouryagupta
Copy link

@orestislampridis yes you are right. I tried it on macOS too. Same issue...

ajctrl added a commit to ajctrl/twint that referenced this issue Dec 16, 2020
@data-z
Copy link

data-z commented Dec 17, 2020

how do we install the new commits?

@sukioral
Copy link

Getting same problem again

@orestislampridis
Copy link

@data-z "pip uninstall twint" and then "pip install git+git://github.com/ajctrl/twint@patch-1". It works for me now!

@sukioral
Copy link

RefreshTokenException: Could not find the Guest token in HTML

@sukioral
Copy link

@data-z "pip uninstall twint" and then "pip install git+git://github.com/ajctrl/twint@patch-1". It works for me now!

Works for me! Thanks!

@data-z
Copy link

data-z commented Dec 17, 2020

@sukioral Thanks works for me too.

@xiaozhouliu
Copy link

@orestislampridis Thanks, it works!

innocentius added a commit to innocentius/twint that referenced this issue Dec 17, 2020
@irisdemented
Copy link

@data-z "pip uninstall twint" and then "pip install git+git://github.com/ajctrl/twint@patch-1". It works for me now!

This worked for me too! Thank you 👍

@WjcSoso0928
Copy link

@data-z "pip uninstall twint" and then "pip install git+git://github.com/ajctrl/twint@patch-1". It works for me now!

I use this method, but I get new error
Error Code:

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.twitter.com:443 ssl:True [Network is unreachable]

I don't know how to fix it

@patrickh217
Copy link

I tried installing it with pip install git+git://github.com/ajctrl/twint@patch-1 but it did not work at first. Then I simply added the line code directly in the script that @ajctrl changed in his pull request. after this little change, it is working for me.

Many thanks

pielco11 pushed a commit that referenced this issue Dec 17, 2020
@data-z
Copy link

data-z commented Dec 17, 2020 via email

@Vickycats
Copy link

Vickycats commented Dec 18, 2020

Hi Please could someone give a command line instruction for installing the current version with the patch since pip install git+git://github.com/ajctrl/twint@patch-1 no longer works. I have manually added the new version of Token.py from git, without doing a full Twint re-install but I am getting inconsistent results. For example in the code below, the output works fine if the Username is 'realdonaldtrump' or 'kamalaharris' but I get errors for other (existing) users. For example if Username is 'sainsburys' (a large superstore chain in the UK), or most other names I get a keyerror on the url:

_usr.url = ur['data']['user']['legacy']['url']
KeyError: 'url'

Less often it fails with 'cannot find the Guest token'.

Code used:

c = twint.Config()
c.Username = 'realdonaldtrump' # works for some not for others. Most not working.
c.Store_object = True
c.Store_object_users_list = []
c.User_full = True
twint.run.Lookup(c)

@rutvikprajapati
Copy link

@Vickycats I manually added the new version of Token.py and now got the below error

CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1****

@subasish
Copy link

Finding similar error code after updating token.py

@agombert
Copy link

agombert commented Jan 4, 2021

Same problem on local, even after updating with the patch mentioned above. Anyone got a solution?

@olof98johansson
Copy link

Same problem on local, even after updating with the patch mentioned above. Anyone got a solution?

For me, the above update didn't work either, but uninstalling twint and then install via

pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint

worked now!

@KazimTibetSar
Copy link

Same problem on local, even after updating with the patch mentioned above. Anyone got a solution?

For me, the above update didn't work either, but uninstalling twint and then install via

pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint

worked now!

at python 3.9.0 i wrote pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint but it didnt worked

@olof98johansson
Copy link

Same problem on local, even after updating with the patch mentioned above. Anyone got a solution?

For me, the above update didn't work either, but uninstalling twint and then install via
pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint
worked now!

at python 3.9.0 i wrote pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint but it didnt worked

Yeah ok :( I use python 3.7.4

@mengyao-liu
Copy link

I use Python 3.9 on a Mac and I have solved this problem by maybe one of the following two steps:

In twint/token.py, change
_self.session.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'})
to
self._session.headers.update({'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11.1; rv:85.0) Gecko/20100101 Firefox/85.0'})

then uninstall and reinstall twint.

It works for me!

@DenisOgr
Copy link

DenisOgr commented Feb 19, 2021

Hi all.
I got this error only when running my code in the Google Cloud Function. On my Mac, it works well.
I fixed it similarly as described above, changed the _self.session.headers.
But I changed it to a Linux browser, not Mac or Windows. I changed:

self.token._session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux ppc64le; rv:75.0) Gecko/20100101 Firefox/75.0'})

I guess the Twitter platform checks the client operating system and if it differs from session.headers, it raises an error.
My code works well without twint.token.RefreshTokenException on Linux (on GCP) and Mac platforms.

@konnextv
Copy link

konnextv commented Mar 2, 2021

Heads up: @DenisOgr 's method works for me inside a Google Cloud Function, but only using python37 as the environment.

EDIT: nevermind, doesn't work with 3.7 either, still getting "Could not find the Guest token in HTML"

@HAKANMAZI
Copy link

still same error

raise RefreshTokenException('Could not find the Guest token
in HTML')
2021-04-18T21:50:03.559085+00:00 app[web.1]: twint.token.RefreshTokenException: Could not find the Guest
token in HTML
2021-04-18T21:50:03.562041+00:00 app[web.1]: 10.47.235.178 - - [18/Apr/2021:21:50:03 +0000] "POST / HTTP/1.1" 500 290 "https://snscrape.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36"

@himanshudabas
Copy link
Contributor

Hi,
please check this comment.
also you can go through the thread of this comment to get a better understanding of why and when this Guest token issue occurs.
I have also mentioned a workaround in the comment.

@prhbrt
Copy link

prhbrt commented Sep 1, 2021

@data-z "pip uninstall twint" and then "pip install git+git://github.com/ajctrl/twint@patch-1". It works for me now!

This patch is pulled into twint now. #1075

@Brata11
Copy link

Brata11 commented Dec 21, 2021

This is the error I am getting using Jupyter Notebook

Collecting git+git://github.com/ajctrl/twint@patch-1
Cloning git://github.com/ajctrl/twint (to revision patch-1) to /tmp/pip-req-build-7ew6pbd5
Running command git clone -q git://github.com/ajctrl/twint /tmp/pip-req-build-7ew6pbd5
WARNING: Did not find branch or tag 'patch-1', assuming revision or ref.
Running command git checkout -q patch-1
error: pathspec 'patch-1' did not match any file(s) known to git.
WARNING: Discarding git+git://github.com/ajctrl/twint@patch-1. Command errored out with exit status 1: git checkout -q patch-1 Check the logs for full command output.
ERROR: Command errored out with exit status 1: git checkout -q patch-1 Check the logs for full command output.

@magikarp171
Copy link

This is the error I am getting using Jupyter Notebook

Collecting git+git://github.com/ajctrl/twint@patch-1 Cloning git://github.com/ajctrl/twint (to revision patch-1) to /tmp/pip-req-build-7ew6pbd5 Running command git clone -q git://github.com/ajctrl/twint /tmp/pip-req-build-7ew6pbd5 WARNING: Did not find branch or tag 'patch-1', assuming revision or ref. Running command git checkout -q patch-1 error: pathspec 'patch-1' did not match any file(s) known to git. WARNING: Discarding git+git://github.com/ajctrl/twint@patch-1. Command errored out with exit status 1: git checkout -q patch-1 Check the logs for full command output. ERROR: Command errored out with exit status 1: git checkout -q patch-1 Check the logs for full command output.

I am getting the same error here

@febrizky
Copy link

febrizky commented Jan 2, 2022

Hi, I'm still getting this error RefreshTokenException: Could not find the Guest token in HTML, try to change __self.session.headers based on here still doesn't work. Does anybody know which user agent string that I should use for Windows 10 x64, and Google Chrome version 96.0.4664.110 ? Thank you.

@philliplumod
Copy link

Same problem on local, even after updating with the patch mentioned above. Anyone got a solution?

For me, the above update didn't work either, but uninstalling twint and then install via
pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint
worked now!

at python 3.9.0 i wrote pip install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint but it didnt worked

still not fixt for me python 3.8

@M4573RN04H
Copy link

Has anyone found a workaround yet? It randomly works 50% of the time 10% of the time. The other 90% it does not work 100% of the time.

@moxak
Copy link

moxak commented Jan 12, 2022

I modified token.py and it worked without error. please try it below.

  1. download token.py via fixed token.py
  2. open directory of twint lib
  3. move new one to twint lib dir
  4. replace it

[postscript]
Since it appeared that getting the guest token using html was failing, I tried to get the guest token using another method.

Even if it works, there may be a slight change in behavior of twint.

@kk0walski
Copy link

  1. fixed token.py

It worked for me.

nouseforacode added a commit to nouseforacode/twint that referenced this issue Jan 12, 2022
@moxak
Copy link

moxak commented Jan 12, 2022

added lines for catching RefreshTokenException

@M4573RN04H
Copy link

If anyone still has an issue there is a whole thread with multiple solutions here #1320

@ljhOfGithub
Copy link

ljhOfGithub commented Apr 9, 2022

What's the use of this exception? Can I comment it out?
'# raise RefreshTokenException('Could not find the Guest token in HTML')'

mike-qualifai added a commit to brightfieldgroup/twint that referenced this issue Mar 7, 2023
Changes to token.py to fix exception as indicated here twintproject#1061 (comment)
@Salmanshabbir
Copy link

RefreshTokenException: Could not find the Guest token in HTML
Can anyone tell about this error how to solve this please if someone now tell if would be very helpfull

@samuel-storri
Copy link

I modified token.py and it worked without error. please try it below.

  1. download token.py via fixed token.py
  2. open directory of twint lib
  3. move new one to twint lib dir
  4. replace it

[postscript] Since it appeared that getting the guest token using html was failing, I tried to get the guest token using another method.

Even if it works, there may be a slight change in behavior of twint.

fixed the issue. thanks.

RoCry added a commit to RoCry/twint that referenced this issue Mar 16, 2023
SPraet added a commit to SPraet/twint that referenced this issue Mar 16, 2023
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