-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[ERROR] 'NoneType' object has no attribute 'span' #1498
[ERROR] 'NoneType' object has no attribute 'span' #1498
Comments
Thank you for contributing to PyTube. Please remember to reference Contributing.md |
Same erorre |
Same error |
Hi, I also have the same error, which is weird because it was working fine this entire week, as well as about 30-45 minutes ago. |
I tried using a solution in another similar topic issue, changing get_throttling_function_name in cipher.py , but it did not work. Probably something changed on the youtube side. |
This was working for me up until about an hour ago or so... Did YouTube release a change that brought back the regex issue from last year? |
Same thing happen with me :) |
Same thing here, stopped working overnight! |
The same error occurs here. I tested it around 2 pm (Brasilia time) and it was working perfectly. Now around 6 pm (Brasilia time) it stopped working. |
Same |
Same error... |
Same error |
Everyone please stop posting "+1" or "same error". |
same error too ㅠㅠ something was changed again at Youtube side I tried change func_regex = re.compile(r"function([^)]+)") in parser.py file and but don't work |
Same error! :'( |
Hello Guys. I just asked ChatGPT (4) about this Issue and ChatGPT said, that we need to update the regular expression in the get_throttling_function_name... function, so that it can analyze the YouTube Java Script file. It has something to do with the base.js file. I am not so familiar with java script (actually I don't know anything), so I can't extract the new regular expression from that base.js file. It has more than 120000 lines by the way. I hope that anyone who understands Java Script can do something with that Information and update the regular expression in the python file. |
Do you know where this base.js file is? |
I just patched this error by simply modifying {home}/.local/lib/python3.7/site-packages/pytube/cipher.py
to
And everything works fine. |
Can you put in a pull request for that please? |
Thank you very much! It worked perfectly here. I have no idea how this change fixed the bug (if you want to explain that would be great), but it worked perfectly anyway. |
Hello, can you please create a pull request for this fix? Thank you for figuring it out :) |
TBH, I have no idea why this works. |
Resolves pytube#1498 by modifying 'cipher.py' line 411 to "transform_plan_raw = js". pytube#1498 All credit goes to https://github.com/dark9ive for fixing the issue.
I have opened a pull request which should solve this issue. Credit to @dark9ive for the fix. |
Resolve Pytube Issue pytube#1498
Thanks for your help. BTW, I think I can give a simple explain about how I find this solution. Fortunately it works, otherwise I would have to sleep 1 or 2 hours less. |
ty for bug
workiing because we got gull js code and regix got our streams close the topic |
Hi, So I did pip uninstall pytube, and then pip install pytube. Nothing changed at all to fix this error. I had to go into the source code myself and make that change on line 411. I had to find that file cypher.py in "%localappdata%/programs/python/python310/lib/site-packages/pytube" and navigate to line 411 and comment out "transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)" and set it to "transform_plan_raw = js" myself manually. What process should I have done to update and fix the error efficiently? Or was it the right process but this error fix is not yet "official"? |
In my case, i am working on collab, but it doesn't work. |
Monkey patching due to bug found by the community: pytube#1498 (comment)
Same error anyone who have known how to fix it |
|
One line fix based on the above solution (change the file path/python version based on your environment):
If you are using Docker, add this to your Dockerfile:
|
This works fine for me! |
BTW, if anyone wants to hot-plug the fix from @dark9ive #1498 (comment) Here's an example: import re
import mock
from pytube.cipher import get_throttling_function_code
def patched_throttling_plan(js: str):
"""Patch throttling plan, from https://github.com/pytube/pytube/issues/1498"""
raw_code = get_throttling_function_code(js)
transform_start = r"try{"
plan_regex = re.compile(transform_start)
match = plan_regex.search(raw_code)
#transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
transform_plan_raw = js
# Steps are either c[x](c[y]) or c[x](c[y],c[z])
step_start = r"c\[(\d+)\]\(c\[(\d+)\](,c(\[(\d+)\]))?\)"
step_regex = re.compile(step_start)
matches = step_regex.findall(transform_plan_raw)
transform_steps = []
for match in matches:
if match[4] != '':
transform_steps.append((match[0],match[1],match[4]))
else:
transform_steps.append((match[0],match[1]))
return transform_steps
with mock.patch('pytube.cipher.get_throttling_plan', patched_throttling_plan):
from pytube import YouTube
url = 'https://www.youtube.com/watch?v=ZBVrPWwSlRM'
video = YouTube(url)
audio = video.streams.filter(only_audio=True, file_extension='mp4')[0]
audio.download() |
It works for me. Solve the problem on iPad. Thanks @alvations |
People using Docker or some CI/CD tools for installing can use a wheel file to install the updated version until this fix gets into an official release. Download this wheel file, move it to appropriate location in your project/ repo and update your requirements.txt accordingly. To get the wheel file I cloned @JLeopolt 's forked repo and ran the following commands.
|
But where is cipher.py file in android? |
about [ERROR] 'NoneType' object has no attribute 'span'
|
Still working today |
IT STARTED WORKING AGAIN!!!!!!!!!!! |
no, I just modified it in my repository and didn't touch the code on Pytube. |
It works! Thank 🎇 |
you are my hero thank you so much |
Hi!
I'm using the latest version, and it worked well until a few days ago. but I got this error today many times while downloading some youtube videos.
I looked into this issue pages and I suspect this is a recurring issue when google changes the js file from their end. I would appreciate it if anyone could provide a solution. Thanks!
File "/usr/local/lib/python3.8/dist-packages/pytube/cipher.py", line 360, in get_throttling_plan', ' raw_code = get_throttling_function_code(js)', ' File "/usr/local/lib/python3.8/dist-packages/pytube/cipher.py", line 277, in get_throttling_function_code', " code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')", "AttributeError: 'NoneType' object has no attribute 'span'"]
The text was updated successfully, but these errors were encountered: