JSON parsing error
See original GitHub issueI get these errors when trying to download certain videos. I don’t know if it’s the fault of your code or of malformed JSON on youtube’s side.
Traceback (most recent call last):
File "experiment_scripts/test_each_video.py", line 52, in test_video_id
yt = pytube.YouTube(video_url)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 88, in __init__
self.prefetch_init()
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 96, in prefetch_init
self.prefetch()
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 174, in prefetch
self.js_url = extract.js_url(self.watch_html, self.age_restricted)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/extract.py", line 147, in js_url
ytplayer_config = get_ytplayer_config(html, age_restricted)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/extract.py", line 196, in get_ytplayer_config
return json.loads(yt_player_config)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/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 17575 (char 17574)
for video https://www.youtube.com/watch?v=qRNqJ5I6PYI&has_verified=1
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 133, in init
mixins.apply_signature(self.player_config_args, fmt, self.js)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/mixins.py", line 53, in apply_signature
raise TypeError('JS is None')
TypeError: JS is None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "experiment_scripts/test_each_video.py", line 52, in test_video_id
yt = pytube.YouTube(video_url)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 88, in __init__
self.prefetch_init()
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 97, in prefetch_init
self.init()
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/__main__.py", line 136, in init
self.embed_html, self.age_restricted,
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/extract.py", line 147, in js_url
ytplayer_config = get_ytplayer_config(html, age_restricted)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/extract.py", line 195, in get_ytplayer_config
yt_player_config = regex_search(pattern, html, group=1)
File "/home/xkcd/miniconda3/envs/video-env/lib/python3.7/site-packages/pytube/helpers.py", line 65, in regex_search
.format(pattern=pattern),
pytube.exceptions.RegexMatchError: regex pattern (;yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})(,'EXPERIMENT_FLAGS'|;)) had zero matches
for video https://www.youtube.com/watch?v=jZLwVPakzwM&has_verified=1
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >How to handle invalid JSON parse error properly.
The most common way to handle JSON parse error is using try-catch block. If the JSON string is valid, it will return a...
Read more >SyntaxError: JSON.parse: bad parsing Breaking Your Code ...
In JavaScript, when passing JSON to the JSON.parse() method, the method expects properly formatted JSON as the first argument. When it detects ...
Read more >What Is JSON and How to Handle an “Unexpected Token” Error
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
Read more >JSON Parsing Error - Stack Overflow
try this code, JSON.parse() method is not able to handle string which is in a single quote as ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes I’m facing same problem. Anyone please help me
Hi @danielgordon10, @jimmyxp01 , @kylefoley76
Am closing issue as it has been quite a while – feel free to reopen if this issue still exists 😄
Thanks