Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
terry-tong opened this issue Nov 11, 2020 · 16 comments

Comments

@terry-tong
Copy link

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?

@github-actions
Copy link

Thank you for contributing to PyTube. Please remember to reference Contributing.md

@tfdahlin
Copy link
Collaborator

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.

@joshgarde
Copy link

@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

@terry-tong
Copy link
Author

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

@chandeepadissanayake
Copy link

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.

This doesn't seem to work now. I'm attaching the output I get.

image

@tfdahlin
Copy link
Collaborator

tfdahlin commented Dec 9, 2020

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

@snowblinkrx
Copy link

just updated with the new version, still have the same problem:
RegexMatchError: get_ytplayer_config: could not find match for config_patterns, setconfig_patterns

@chandeepadissanayake
Copy link

Thank you @tfdahlin for the clarification. I was installing using PyPI which may hasn't been updated yet.
@snowblinkrx Probably you might have installed using PyPI too, apologies in advance if that's not the case. Also you might be trying to download a stream, which is apparently failing too.

@snowblinkrx
Copy link

I am using AWS, sagemaker and lambda function, did modify the request.py, updated the package, none of them worked.

@tfdahlin
Copy link
Collaborator

tfdahlin commented Dec 9, 2020

@snowblinkrx if you run print(pytube.__version__) does it show '10.1.0'?

@snowblinkrx
Copy link

I am using : 9.7.2

@tfdahlin
Copy link
Collaborator

tfdahlin commented Dec 9, 2020

There's your problem, you're using an outdated version of pytube. The pytube version currently available on pypi is 10.0.0, and the most recent version available from source is 10.1.0.

@snowblinkrx
Copy link

updated, and yes, that worked. thanks!

@pytube pytube deleted a comment from zaid-kamil Jan 31, 2021
@pauloreis-ds
Copy link

pytube 10.5.0
pip install git+https://github.com/nficano/pytube worked just fine! Thank You! \o\ |o| /o/ However...

Traceback (most recent call last):
File "C:/Users/pc/Desktop/PAULINHO/PyCharmProjects/YouTubeDownloader/downloader.py", line 16, in
youtube_downloader = YouTube(youtube_link)#.streams.first().download()
File "C:\Users\pc\Desktop\PAULINHO\YouTubeDownloader\lib\site-packages\pytube_main_.py", line 105, in init
self.descramble()
File "C:\Users\pc\Desktop\PAULINHO\YouTubeDownloader\lib\site-packages\pytube_main_.py", line 177, in descramble
apply_signature(self.player_config_args, fmt, self.js)
File "C:\Users\pc\Desktop\PAULINHO\YouTubeDownloader\lib\site-packages\pytube\extract.py", line 370, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\pc\Desktop\PAULINHO\YouTubeDownloader\lib\site-packages\pytube\cipher.py", line 36, in init
var, _ = self.transform_plan[0].split(".")
ValueError: not enough values to unpack (expected 2, got 1)

little help?

@tfdahlin
Copy link
Collaborator

hi @pauloreis-ds, I just merged the fix for that problem

@pauloreis-ds
Copy link

My Hero! Thank You.

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

No branches or pull requests

6 participants