pytube: json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 28 (char 27)

Hello! Inexperienced Github & Python user here! I’m running into an issue pulling in a specific video from YouTube. I’m running Pytube 9.7.0 on PyCharm Community Edition 2020.1.4. The code is as follows:

from pytube import YouTube

yt = YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(yt.title)

Expect output should be:

Rick Astley - Never Gonna Give You Up (Video)

But instead, I’m getting:

Traceback (most recent call last):
  File "C:/Users/user/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/scratch.py", line 3, in <module>
    yt = YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
  File "C:\Users\user\Projects\PycharmProjects\venv\lib\site-packages\pytube\__main__.py", line 103, in __init__
    self.descramble()
  File "C:\Users\user\Projects\PycharmProjects\venv\lib\site-packages\pytube\__main__.py", line 123, in descramble
    self.player_config_args = get_ytplayer_config(self.watch_html)[
  File "C:\Users\user\Projects\PycharmProjects\venv\lib\site-packages\pytube\extract.py", line 203, in get_ytplayer_config
    return json.loads(yt_player_config)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 28 (char 27)

Process finished with exit code 1

The code appears to work for other videos as intended:

from pytube import YouTube

yt = YouTube("https://www.youtube.com/watch?v=2lAe1cqCOXo&t")
print(yt.title)
YouTube Rewind 2019: For the Record | #YouTubeRewind

Process finished with exit code 0

I don’t think I have the programming experience to decipher the error traceback. Is anyone else able to replicate this issue?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16

Most upvoted comments

hi @chandeepadissanayake this is because that branch has been merged into the main repo. The command you want to use now is pip install git+https://github.com/nficano/pytube. That previous command was to install an experimental branch

updated, and yes, that worked. thanks!

@tfdahlin The experimental branch works like a charm! Thanks for the help. Closing this issue now.

@tfdahlin Just tested out the branch and it’s working great! Tried it on a sample size of about 300 videos so far and I’m not getting any issues here

hi @terry-tong we’re actually working to try to resolve this issue right now! There’s a number of videos where we’ve seen this issue, so myself and a-czyrny have been working on a fix for it. There’s a pull request right now that’s trying to fix the problem, and it seems to be working, once I hear back from the other person, it should be merged pretty quickly.

If you’re interested in trying out this experimental branch, I believe you should be able to install it with the following command in pycharm’s terminal window: pip install git+https://github.com/a-czyrny/pytube@additional_playerconfig_extraction

Otherwise, we’ll hopefully have the fixes in the main repository in the next couple days, and I’m hoping that we’ll have something new pushed to pypi (so you can just pip install pytube) within the next week.