mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.
GNU General Public License v3.0
8.12k stars 642 forks source link

Crash when exceeding the quota #997

Closed orbea closed 4 years ago

orbea commented 5 years ago

mps-youtube will crash when the quota has been exceeded which sometimes happens.

Issue / Suggestion

$ mpsyt /test
Traceback (most recent call last):
  File "/usr/lib64/python3.7/site-packages/pafy/util.py", line 34, in call_gdata
    data = g.opener.open(url).read().decode('utf-8')
  File "/usr/lib64/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib64/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib64/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib64/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/mpsyt", line 11, in <module>
    load_entry_point('mps-youtube==0.2.8', 'console_scripts', 'mpsyt')()
  File "/usr/lib64/python3.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib64/python3.7/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/usr/lib64/python3.7/site-packages/pkg_resources/__init__.py", line 2434, in load
    return self.resolve()
  File "/usr/lib64/python3.7/site-packages/pkg_resources/__init__.py", line 2440, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib64/python3.7/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/lib64/python3.7/site-packages/mps_youtube/init.py", line 59, in init
    cache.load()
  File "/usr/lib64/python3.7/site-packages/mps_youtube/cache.py", line 34, in load
    pafy.load_cache(cached['pafy'])
  File "/usr/lib64/python3.7/site-packages/pafy/pafy.py", line 184, in load_cache
    set_categories(newcache.get('categories', {}))
  File "/usr/lib64/python3.7/site-packages/pafy/pafy.py", line 171, in set_categories
    catinfo = call_gdata('videoCategories', query)
  File "/usr/lib64/python3.7/site-packages/pafy/util.py", line 42, in call_gdata
    raise GdataError(errmsg)
pafy.util.GdataError: Youtube Error 403: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.

Your Environment

I am running Slackware64-current.

$ mpsyt --version
mpsyt version      : 0.2.8
   notes           : released 17 February 2018
pafy version       : 0.5.4 (youtube-dl backend)
youtube-dl version : 2019.07.12
Python version     : 3.7.3 (default, Apr  3 2019, 21:34:18) 
[GCC 8.3.0]
Processor          : AMD FX(tm)-6350 Six-Core Processor
Machine type       : x86_64
Architecture       : 64bit, ELF
Platform           : Linux-5.1.16-x86_64-AMD_FX-tm-6350_Six-Core_Processor-with-slackware-14.2
sys.stdout.enc     : UTF-8
default enc        : utf-8
Config dir         : /home/orbea/.config/mps-youtube
env:TERM           : rxvt-256color
env:SHELL          : /bin/bash
env:LANG           : en_US.utf8
njiang7 commented 5 years ago

A possible fix could be to implement an option of using personal Youtube API keys?

ids1024 commented 5 years ago

A possible fix could be to implement an option of using personal Youtube API keys?

There already is.

set api_key <key>

orbea commented 5 years ago

A possible fix could be to implement an option of using personal Youtube API keys?

I am not reporting that I am running into the quota, but that mps-youtube is crashing when it reaches the limit. This used to fail gracefully, I would guess something in youtube or youtube-dl changed.

pucerpocok commented 5 years ago

Hi, Yes, there is an option to set the api_key, and for example I set it earlier. However it seems when mpsyt is started the default key is used, which results in the crash with this error message (please notice the project ID at the end): Youtube Error 403: Daily Limit Exceeded. The quota will be reset at midnight Pacific Time (PT). You may monitor your quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/youtube.googleapis.com/quotas?project=422897895433 While in the .config/mps-youtube/config file I see my own api_key.

orbea commented 5 years ago

I am not sure what happened, but I am no longer getting a crash and have not changed anything regarding youtube-dl or mps-youtube.

Error fetching data. Possible network issue.
Youtube Error 403: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.
benburkhart1 commented 5 years ago

I can confirm this is occurring even with a custom API key set.

The offending code is here:

https://github.com/mps-youtube/pafy/blob/develop/pafy/util.py#L30

It's reading from g and is not something you can override:

https://github.com/mps-youtube/pafy/blob/develop/pafy/g.py#L24

If you need a quick fix until this is patched, you can just edit the line in util.py to be

qs['key'] = "yourapikey"

overnxt commented 5 years ago

I update it on: /home/{your user}/.local/lib/python3.7/site-packages/pafy/g.py on line "api_key = ", adding my api key and now is working.

adamnovak commented 5 years ago

Deleting ~/.config/mps-youtube/cache_py_3.6.8 allowed me to start up the program and work around the crash. Then I could go in and use set api_key XXXXX to install the key I got following the instructions in https://github.com/mps-youtube/mps-youtube/issues/551#issuecomment-513455722. Then after restarting mpsyt, my new key was used and the program started working again.

So something is wrong in the handling of that cache file, I suppose.

itanoss commented 5 years ago

In my case, my own api key was created 3 years ago. With that key, mps always show exceeding quota message, but no api usage recorded on api console.

After recreating both project and api key on the console, everything works fine.

trongthanh commented 5 years ago

I just fixed this using @adamnovak guide above. Just list ~/.config/mps-youtube/ and remove whatever cache_py_* file there.

I guess when I started mpsyt the first time, I didn't use my own API key, so the default one is cached and used when the app is bootstrapped.

egrieco commented 5 years ago

I was getting the same error when running any command except mpsyt --help. Even mpsyt set was failing.

As @adamnovak and @trongthanh have suggested, I ran the following command:

rm -v ~/.config/mps-youtube/cache_py_*

Now I can run mpsyt and set my own api key.

LaurentDumont commented 4 years ago

I just ran into this but using set allowed me to use my own API key (after generating one). I'm not too sure why the project is bootstraped with a generic key that isn't generated by the user. I'd rather have that step be part of the installation process than random 403 when the quota is reached.

MPS didn't crash but it did error out with a warning.

orbea commented 4 years ago

mpsyt is essentially dead now so w/e...

kurokirasama commented 4 years ago

is there an alternative?_?

Alanthiel commented 3 years ago

For me, I deleted ~/.config/mps-youtube the cache.py file. It tarted working fine