pytube: [BUG] 'NoneType' object has no attribute 'span'
Before creating an issue
Please confirm that you are on the latest version of pytube by installing from the source.
You can do this by running python -m pip install git+https://github.com/pytube/pytube
.
Sometimes, the pypi library repository is not up to date, and your issue may have been fixed already!
Describe the bug I have been running PyTube at different points today with success and fast downloads, but as of about 30 minutes ago I started to get this when I would run it:
'NoneType' object has no attribute 'span'
To Reproduce I have tried on these two links, both of which were working earlier today: -https://www.youtube.com/watch?v=twtGL8WbllM&ab_channel=HarritonRams -https://www.youtube.com/watch?v=mA_3LkF_Cdo&ab_channel=IndianaSRN
Here is the code sample where it is being used:
def download_youtube_video(row, game_id): filename = game_id + ".mp4" try: YouTube(row[0]).streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename=filename) upload_successful = True except Exception as e: print(e) print("HEY, LOOK HERE") print("I'VE GOT SOME BAD NEWS, SADLY") print("YOU'RE GOING TO HAVE TO DOWNLOAD AND UPLOAD THIS ONE MANUALLY") print(row[0]) print(game_id) print("I TRIED TWO DIFFERENT YOUTUBE DOWNLOADER PACKAGES, BLAME THOSE F**** OVER AT GOOGLE FOR THIS")
Expected behavior I expected the video to be downloaded in the same directory as my python script as it was earlier today.
Output
Traceback (most recent call last): File "test.py", line 3, in <module> YouTube("https://www.youtube.com/watch?v=mA_3LkF_Cdo&ab_channel=IndianaSRN").streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename="hello.mp4") File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/__main__.py", line 292, in streams return StreamQuery(self.fmt_streams) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/__main__.py", line 177, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/cipher.py", line 43, in __init__ self.throttling_plan = get_throttling_plan(js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/cipher.py", line 387, in get_throttling_plan raw_code = get_throttling_function_code(js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/cipher.py", line 301, 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'
System information Please provide the following information:
- Python version: Python 3.7.1rc1
- Pytube version: Unsure as the provided way to find this didn’t work
- Command used to install pytube: First was
python -m pip install pytube
but before posting it waspython -m pip install git+https://github.com/pytube/pytube
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 91 (6 by maintainers)
Links to this issue
Commits related to this issue
- bug fix for https://github.com/pytube/pytube/issues/1218 — committed to richmengsix/pytube by richmengsix 2 years ago
- Temporary hotfix for pytube * https://github.com/pytube/pytube/issues/1218#issuecomment-1026490635 Should take care of missing regex match. — committed to glubsy/livestream_saver by glubsy 2 years ago
- Fix regex to find throttle function name The javascript now stores the throttling function name in an array. Fix https://github.com/pytube/pytube/issues/1218 — committed to glubsy/pytube by glubsy 2 years ago
- Update cipher.py resolved these #1243 #1240 #1233 #1228 #1225 #1218 , as of 2022-02-08 — committed to ifahadone/pytube by ifahadone 2 years ago
- Fix regex to find throttle function name (#1222) * Fix regex to find throttle function name The javascript now stores the throttling function name in an array. Fix https://github.com/pytube/pytub... — committed to pytube/pytube by glubsy 2 years ago
I think the javascipt changed. If you search for Bpa, you don’t find a function. Instead you get
Thus Bpa is an array with the function “iha” in location zero . If you use iha for the name, you get a function. I kludged line 293 of cipher.py to go from
to
And I now its working.
I’m not sure how to correctly change the code yet, but if I figure out a proper patch I’ll post it.
Dear @mahdizarepro in the
get_throttling_function_code
function in the cipher.py file I have changed name =“iha” to name = “jha” and now it works for me… Until the next change ‘kha’ 😃 do not hesitate to use my repo :Mine worked with this, working today fine
pip uninstall pytube pip install git+https://github.com/glubsy/pytube@nfunc_regex_patch
name="iha"
fix did not work for me either. Looks like something might have changed in the past few hours.None of the fix here are working for me, I’m out of solution right now
And you will bang your head again as soon as the javascript gets recompiled. Better use this branch instead https://github.com/glubsy/pytube/tree/nfunc_regex_patch
replacing ‘iha’ for ‘jha’ have worked for me too
Changing :
is there any soln other than this (name = “iha” fix has stopped working)
name = “iha” fix has stopped working since today morning (03 JAN 11:05 IST). Worked fine till yesterday
“iha” fix didn’t work for me either 😦
Keeping an eye on this, hopefully it gets figured out soon.
I created a fork with the earlier proposed solution if anyone need it. https://github.com/oleksandr-shvab/pytube
Yes, the regex is searching for a throttling function
Bpa\[0\]=function\(\w\)
but new function looks like this&&(b=Bpa[0](b),a.set("n",b),Bpa.length||iha(""))}};
@glubsy no doubt, here we got full of immature programmers who claims to be superb😂
Just did a fresh pip, pytube, pydub reinstall and this issue has gone away.
@rishabh3354 this has nothing to do with this issue.
the specific itag you are trying to use has no filesize value, therefore you are getting KeyError: ‘content-length’.
i suppose, this will get the job done
and please be respectful to others,
@glubsy @rmerzouki
It is failing for Some streams objects
HOW TO REPLICATE
video link
https://www.youtube.com/watch?v=twtGL8WbllM
this stream obj is failing which in no.8 in my case (itag=“160”).
<Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400b" progressive="False" type="video">
YouTube('https://www.youtube.com/watch?v=twtGL8WbllM').streams[8].download("/home/warlord/testing", "Basketball.mp4")
ERROR OUTPUT
Error is when i try to download Error: ‘content-length’ video link: https://www.youtube.com/watch?v=twtGL8WbllM
@rishabh3354 it works. Show us the error you get? I’m not getting any error.
Dear @quantum-hash use this branch https://github.com/glubsy/pytube/tree/nfunc_regex_patch or do this
It’s not working for me neither. I tried suggested solutions here and non of them worked
Solutions tried:
Error msg:
Video: https://www.youtube.com/watch?v=8bAzi4zIqK0
is pytube is working for anyone, Please share pytube patched branch so that we will be able to install through pip
Latest error is in cypher.py not parser.py
Hey @rishabh3354 please don’t be rude to other members of the repo - there is a ban functionality.
@eliorc Hey want to confirm the question – is the fix working but not released in PyPI?
this is not fixed, dont close it bro… dont make us fool. lol
you have proved yourself, i am not expecting answers from you btw
This fix is not working for this video https://www.youtube.com/watch?v=twtGL8WbllM
Thanks it also works for me
Thanks, it works
its work for me thanks
thanks! I spent a morning banging my head with this problem
If you people cared to look around before whining like blind moles, you would have noticed there is a pending pull request with the fix to this problem at https://github.com/pytube/pytube/pull/1222
The error only happens in me every time I do “YouTube(url).streams” while “YouTube(url).streaming_data” can return object
name = “iha” seemed to be working fine at the time of previous issue, however, I think now we have got new one.
@rishabh3354 try this :
Strange. It’s working for me. I used command
pipenv install -e git+https://github.com/oleksandr-shvab/pytube#egg=pytube
and then rebuild the container.