pytube: [BUG]'NoneType' object has no attribute 'span'

i just got the same error 3 days ago. I changed name = 'hha' and it worked. now it shows the same error. please help me out ad give a permanent solution. till yesterday it worked well, but today it seems to be fixed

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 46

Commits related to this issue

Most upvoted comments

name = re.escape(get_throttling_function_name(js))

then replace get_throttling_function_name function as follows

def get_throttling_function_name(js: str) -> str:
    """Extract the name of the function that computes the throttling parameter.

    :param str js:
        The contents of the base.js asset file.
    :rtype: str
    :returns:
        The name of the function used to compute the throttling parameter.
    """
    function_patterns = [
        # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
        # a.C&&(b=a.get("n"))&&(b=Dea(b),a.set("n",b))}};
        # In above case, `Dea` is the relevant function name
        r'a\.[A-Z]&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\)',
    ]
    logger.debug('Finding throttling function name')
    for pattern in function_patterns:
        regex = re.compile(pattern)
        function_match = regex.search(js)
        if function_match:
            logger.debug("finished regex search, matched: %s", pattern)
            function_name = function_match.group(1)
            is_Array = True if '[' in function_name or ']' in function_name else False
            if is_Array:
                index = int(re.findall(r'\d+', function_name)[0])
                name = function_name.split('[')[0]
                pattern = r"var %s=\[(.*?)\];" % name
                regex = re.compile(pattern)
                return regex.search(js).group(1).split(',')[index]
            else:
                return function_name

    raise RegexMatchError(
        caller="get_throttling_function_name", pattern="multiple"
    )

i think we have to shift to youtube-dl

Cipher.py

def get_throttling_function_code(js: str) -> str: name = ‘sha’

Today short way ))))

For show it s working: https://youtube.impropy.me/

@ifahadone

Everything is working .

People’s can check it live.

https://youtube.impropy.me/

It 's Fahad solved version…

name = re.escape(get_throttling_function_name(js))

then replace get_throttling_function_name function as follows

def get_throttling_function_name(js: str) -> str:
    """Extract the name of the function that computes the throttling parameter.

    :param str js:
        The contents of the base.js asset file.
    :rtype: str
    :returns:
        The name of the function used to compute the throttling parameter.
    """
    function_patterns = [
        # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
        # a.C&&(b=a.get("n"))&&(b=Dea(b),a.set("n",b))}};
        # In above case, `Dea` is the relevant function name
        r'a\.[A-Z]&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\)',
    ]
    logger.debug('Finding throttling function name')
    for pattern in function_patterns:
        regex = re.compile(pattern)
        function_match = regex.search(js)
        if function_match:
            logger.debug("finished regex search, matched: %s", pattern)
            function_name = function_match.group(1)
            is_Array = True if '[' or ']' in function_name else False
            if is_Array:
                index = int(re.findall(r'\d+', function_name)[0])
                name = function_name.split('[')[0]
                pattern = r"var %s=\[(.*?)\];" % name
                regex = re.compile(pattern)
                return regex.search(js).group(1).split(',')[index]
            else:
                return function_name

    raise RegexMatchError(
        caller="get_throttling_function_name", pattern="multiple"
    )

This works for me!! For those of you confused as I was about the name = re.escape(get_throttling_function_name(js)) part, You are not to change that in the file. Here is what I did:

  1. You open the cipher.py file in the pytube directory in whatever text editor you use
  2. Find the ‘get_throttling_function_name’ function
  3. Delete that function definition and replace with what is above

Hope this works for you as well! And thank you guys for sharing this solution, It was driving me crazy.

Cipher.py

def get_throttling_function_code(js: str) -> str: name = ‘sha’

Today short way ))))

For show it s working: https://youtube.impropy.me/

This worked for me, thanks.

name = re.escape(get_throttling_function_name(js))

then replace get_throttling_function_name function as follows

def get_throttling_function_name(js: str) -> str:
    """Extract the name of the function that computes the throttling parameter.

    :param str js:
        The contents of the base.js asset file.
    :rtype: str
    :returns:
        The name of the function used to compute the throttling parameter.
    """
    function_patterns = [
        # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
        # a.C&&(b=a.get("n"))&&(b=Dea(b),a.set("n",b))}};
        # In above case, `Dea` is the relevant function name
        r'a\.[A-Z]&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\)',
    ]
    logger.debug('Finding throttling function name')
    for pattern in function_patterns:
        regex = re.compile(pattern)
        function_match = regex.search(js)
        if function_match:
            logger.debug("finished regex search, matched: %s", pattern)
            function_name = function_match.group(1)
            is_Array = True if '[' or ']' in function_name else False
            if is_Array:
                index = int(re.findall(r'\d+', function_name)[0])
                name = function_name.split('[')[0]
                pattern = r"var %s=\[(.*?)\];" % name
                regex = re.compile(pattern)
                return regex.search(js).group(1).split(',')[index]
            else:
                return function_name

    raise RegexMatchError(
        caller="get_throttling_function_name", pattern="multiple"
    )

This Work Thanks Bro 😄

is_Array = True if ‘[’ or ‘]’ in function_name else False

Are you serious? What language are you trying to write this in? This expression is always True in python. If you meant to search for brackets, in python it would look something like this:

is_Array = ‘[’ in function_name or ‘]’ in function_name

name = re.escape(get_throttling_function_name(js))

then replace get_throttling_function_name function as follows

def get_throttling_function_name(js: str) -> str:
    """Extract the name of the function that computes the throttling parameter.

    :param str js:
        The contents of the base.js asset file.
    :rtype: str
    :returns:
        The name of the function used to compute the throttling parameter.
    """
    function_patterns = [
        # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
        # a.C&&(b=a.get("n"))&&(b=Dea(b),a.set("n",b))}};
        # In above case, `Dea` is the relevant function name
        r'a\.[A-Z]&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\)',
    ]
    logger.debug('Finding throttling function name')
    for pattern in function_patterns:
        regex = re.compile(pattern)
        function_match = regex.search(js)
        if function_match:
            logger.debug("finished regex search, matched: %s", pattern)
            function_name = function_match.group(1)
            is_Array = True if '[' or ']' in function_name else False
            if is_Array:
                index = int(re.findall(r'\d+', function_name)[0])
                name = function_name.split('[')[0]
                pattern = r"var %s=\[(.*?)\];" % name
                regex = re.compile(pattern)
                return regex.search(js).group(1).split(',')[index]
            else:
                return function_name

    raise RegexMatchError(
        caller="get_throttling_function_name", pattern="multiple"
    )

@ifahadone can you create a PR?

I’m getting a 500 Server Error: image

This is the used URL: https://www.youtube.com/watch?v=8bAzi4zIqK0

I tried bringing latest changes from pytube and I’m getting this error when downloading the 720p: pip install git+https://github.com/pytube/pytube.git

streams = yt.streams.filter(progressive=True, file_extension='mp4') \
            .order_by('resolution') \
            .desc()
        streams = streams.filter(res='720p').first()
        streams.download(output_path='assets/videos', filename='test.mp4')

Result:

http.client.IncompleteRead: IncompleteRead(1666671 bytes read, 7770513 more expected)

But it works if I download the 360p version 🤔

i need to download 144p of this video, how do i do that, i cant, because lib is breaking…

try this :

video.streams.filter(progressive=True).order_by('resolution').asc()

image

bro, pytube has issue with filesize function with this file, if you remember before downloading the video pytube always hit request filesize api , and it is breaking for this itag only. and this is inbuilt feature of pytube, that is currently breaking.

@rishabh3354

your solution is not wotking with this video. #1218 (comment)

image

your video is not working because of your poor execution of code, the specific itag you are trying to use, has no filesize value, therefore you are getting KeyError: ‘content-length’.

Please don’t spam and mislead the information without proper research and debugging. it will help a lot of people

@CrDevUno what was the video URL that you were trying to download?

This is the sample URL I used in the Google Colab sample: https://www.youtube.com/watch?v=68tSUOL-kVo The OP in the Stack Overflow question did not provide URL samples. Please try with this URL sample or with any other URL you consider for testing. Thank you for you reply.

I have just tested it, it works fine, please check if you are following the steps correctly, you can try any of this : steps or Clone or replace cipher.py

image

Thank you @ifahadone that was quick appreciate it