rdavydov / Twitch-Channel-Points-Miner-v2

A simple script that will watch a stream for you and earn the channel points.
GNU General Public License v3.0
1.1k stars 324 forks source link

AttributeError: 'NoneType' object has no attribute 'group' #487

Closed niruvibes closed 2 months ago

niruvibes commented 2 months ago

Describe the bug

When trying to run the miner, the error "AttributeError: 'NoneType' object has no attribute 'group'" appears

Steps to reproduce

  1. Setup as usual
  2. py run.py
  3. error

Expected behavior

The miner should work with no error?

Operating system

Windows 11 Pro Version 23H2 OS build 22631.3374

Python version

3.12.1

Miner version

1.9.4 (latest?)

Other relevant software versions

No response

Logs

console: https://gist.github.com/niruvibes/ba8f333765bbdf3cef620990ac44b184 log file: https://gist.github.com/niruvibes/957bb23aede7cbf60cb8c7e93cb8321d

Additional context

No response

duey commented 2 months ago

I'm getting the same error. It was last working last week on April 7th. I started it up today from the console without having changed anything.

Operating system

Ubuntu 20.04.6 LTS

uname -a: Linux hpmini600g2 5.15.0-101-generic #111~20.04.1-Ubuntu SMP Mon Mar 11 15:44:43 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Python version

Python 3.8.10

Miner version

Twitch Channel Points Miner v2-1.9.4 (fork by rdavydov)

Logs

Console output: https://gist.github.com/duey/9b228f3394016a6ab1986f6f9edade7b

log file: https://gist.github.com/duey/98f724a0597b615b89edd3f6c2c6c608

duey commented 2 months ago

Ah oops, I jumped the gun. I just did a git pull and now it's working.

Git pull output:

remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (12/12), done. remote: Total 15 (delta 8), reused 5 (delta 3), pack-reused 0 Unpacking objects: 100% (15/15), 5.06 KiB | 1.01 MiB/s, done. From https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2

" edit to add:

Ok, now odd.... I accidentally stopped the bot (by pressing Ctrl-C), started it up again and I got the NoneType error again. Then, after a couple of minutes, I thought I'd try again and now it's working again....

updated log file: https://gist.github.com/duey/f625a3b58b787b1d37dccfab2449e247

xxiiqq commented 2 months ago

I'm getting the same error :(

28Black commented 2 months ago

Same error also here. I'll provide logs if you need more.

Angarv1n commented 2 months ago

Same 😢

ranehal commented 2 months ago

same here, any hotfix?

File "C:\Users\User\Desktop\Twitch-Channel-Points-Miner-v2-1.9.4\TwitchChannelPointsMiner\TwitchChannelPointsMiner.py", line 210, in mine self.run(streamers=streamers, blacklist=blacklist, followers=followers) File "C:\Users\User\Desktop\Twitch-Channel-Points-Miner-v2-1.9.4\TwitchChannelPointsMiner\TwitchChannelPointsMiner.py", line 299, in run self.twitch.check_streamer_online(streamer) File "C:\Users\User\Desktop\Twitch-Channel-Points-Miner-v2-1.9.4\TwitchChannelPointsMiner\classes\Twitch.py", line 182, in check_streamer_online self.get_spade_url(streamer) File "C:\Users\User\Desktop\Twitch-Channel-Points-Miner-v2-1.9.4\TwitchChannelPointsMiner\classes\Twitch.py", line 143, in get_spade_url settings_url = re.search(regex_settings, response).group(1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'group'

fvckgrimm commented 2 months ago

The issue seems to be coming from this class function https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L131-L152

It seems if it doesn't get the settings or the spade url it will throw the error as it returns None instead of the needed urls.

So far, what seems to be working for me is this generated fix giving it retry attempts for getting the urls needed. It's not guaranteed to work as it could just fail {x} times in a row but it gives it a better chance at actually getting them. (could also just increase the max_retries from 5)

you can replace or comment out the old function and place this in its place in the TwitchChannelPointsMiner/classes/Twitch.py file

def get_spade_url(self, streamer):
        from TwitchChannelPointsMiner.constants import USER_AGENTS

        headers = {"User-Agent": USER_AGENTS["Linux"]["FIREFOX"]}
        regex_settings = "(https://static.twitchcdn.net/config/settings.*?js)"
        max_retries = 5
        delay = 5  # Delay in seconds between retries

        for attempt in range(max_retries):
            try:
                main_page_request = requests.get(streamer.streamer_url, headers=headers)
                response = main_page_request.text
                settings_match = re.search(regex_settings, response)
                if settings_match is None:
                    logger.error(f"Failed to find settings URL for streamer {streamer.streamer_url}")
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                settings_url = settings_match.group(1)
                logger.info(f"Found settings URL for streamer {streamer.streamer_url}")

                settings_request = requests.get(settings_url, headers=headers)
                response = settings_request.text
                regex_spade = '"spade_url":"(.*?)"'
                spade_match = re.search(regex_spade, response)
                if spade_match is None:
                    logger.error(f"Failed to find spade URL in settings for streamer {streamer.streamer_url}" )
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                streamer.stream.spade_url = spade_match.group(1)
                logger.info(
                    f"Found spade URL in settings for streamer {streamer.streamer_url}"
                )
                break  # Exit the loop if successful
            except requests.exceptions.RequestException as e:
                logger.error(f"Something went wrong during extraction of 'spade_url': {e}" )
                if attempt < max_retries - 1:  # Don't wait on the last attempt
                    time.sleep(delay)
ranehal commented 2 months ago

The issue seems to be coming from this class function

https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L131-L152

It seems if it doesn't get the settings or the spade url it will throw the error as it returns None instead of the needed urls.

So far, what seems to be working for me is this generated fix giving it retry attempts for getting the urls needed. It's not guaranteed to work as it could just fail {x} times in a row but it gives it a better chance at actually getting them. (could also just increase the max_retries from 5)

you can replace or comment out the old function and place this in its place in the TwitchChannelPointsMiner/classes/Twitch.py file

def get_spade_url(self, streamer):
        from TwitchChannelPointsMiner.constants import USER_AGENTS

        headers = {"User-Agent": USER_AGENTS["Linux"]["FIREFOX"]}
        regex_settings = "(https://static.twitchcdn.net/config/settings.*?js)"
        max_retries = 5
        delay = 5  # Delay in seconds between retries

        for attempt in range(max_retries):
            try:
                main_page_request = requests.get(streamer.streamer_url, headers=headers)
                response = main_page_request.text
                settings_match = re.search(regex_settings, response)
                if settings_match is None:
                    logger.error(f"Failed to find settings URL for streamer {streamer.streamer_url}")
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                settings_url = settings_match.group(1)
                logger.info(f"Found settings URL for streamer {streamer.streamer_url}")

                settings_request = requests.get(settings_url, headers=headers)
                response = settings_request.text
                regex_spade = '"spade_url":"(.*?)"'
                spade_match = re.search(regex_spade, response)
                if spade_match is None:
                    logger.error(f"Failed to find spade URL in settings for streamer {streamer.streamer_url}" )
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                streamer.stream.spade_url = spade_match.group(1)
                logger.info(
                    f"Found spade URL in settings for streamer {streamer.streamer_url}"
                )
                break  # Exit the loop if successful
            except requests.exceptions.RequestException as e:
                logger.error(f"Something went wrong during extraction of 'spade_url': {e}" )
                if attempt < max_retries - 1:  # Don't wait on the last attempt
                    time.sleep(delay)

works thanks

Xaenchan commented 2 months ago

Fix works for me on a bit older version too

need some more tries than 5 for some, so I put 8 as max tries instead

inmispwr commented 2 months ago

fvckgrimm, thanks a lot for your fix, it worked out both on 1.9.3 and on 1.9.4

Petrarka0 commented 2 months ago

is it posiible to cache settings? for hot reboot

Abhay-Cerberus commented 2 months ago

The issue seems to be coming from this class function

https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L131-L152

It seems if it doesn't get the settings or the spade url it will throw the error as it returns None instead of the needed urls.

So far, what seems to be working for me is this generated fix giving it retry attempts for getting the urls needed. It's not guaranteed to work as it could just fail {x} times in a row but it gives it a better chance at actually getting them. (could also just increase the max_retries from 5)

you can replace or comment out the old function and place this in its place in the TwitchChannelPointsMiner/classes/Twitch.py file

def get_spade_url(self, streamer):
        from TwitchChannelPointsMiner.constants import USER_AGENTS

        headers = {"User-Agent": USER_AGENTS["Linux"]["FIREFOX"]}
        regex_settings = "(https://static.twitchcdn.net/config/settings.*?js)"
        max_retries = 5
        delay = 5  # Delay in seconds between retries

        for attempt in range(max_retries):
            try:
                main_page_request = requests.get(streamer.streamer_url, headers=headers)
                response = main_page_request.text
                settings_match = re.search(regex_settings, response)
                if settings_match is None:
                    logger.error(f"Failed to find settings URL for streamer {streamer.streamer_url}")
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                settings_url = settings_match.group(1)
                logger.info(f"Found settings URL for streamer {streamer.streamer_url}")

                settings_request = requests.get(settings_url, headers=headers)
                response = settings_request.text
                regex_spade = '"spade_url":"(.*?)"'
                spade_match = re.search(regex_spade, response)
                if spade_match is None:
                    logger.error(f"Failed to find spade URL in settings for streamer {streamer.streamer_url}" )
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                streamer.stream.spade_url = spade_match.group(1)
                logger.info(
                    f"Found spade URL in settings for streamer {streamer.streamer_url}"
                )
                break  # Exit the loop if successful
            except requests.exceptions.RequestException as e:
                logger.error(f"Something went wrong during extraction of 'spade_url': {e}" )
                if attempt < max_retries - 1:  # Don't wait on the last attempt
                    time.sleep(delay)

was getting the same issue now it works thanks

niruvibes commented 2 months ago

The issue seems to be coming from this class function

https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L131-L152

It seems if it doesn't get the settings or the spade url it will throw the error as it returns None instead of the needed urls.

So far, what seems to be working for me is this generated fix giving it retry attempts for getting the urls needed. It's not guaranteed to work as it could just fail {x} times in a row but it gives it a better chance at actually getting them. (could also just increase the max_retries from 5)

you can replace or comment out the old function and place this in its place in the TwitchChannelPointsMiner/classes/Twitch.py file

def get_spade_url(self, streamer):
        from TwitchChannelPointsMiner.constants import USER_AGENTS

        headers = {"User-Agent": USER_AGENTS["Linux"]["FIREFOX"]}
        regex_settings = "(https://static.twitchcdn.net/config/settings.*?js)"
        max_retries = 5
        delay = 5  # Delay in seconds between retries

        for attempt in range(max_retries):
            try:
                main_page_request = requests.get(streamer.streamer_url, headers=headers)
                response = main_page_request.text
                settings_match = re.search(regex_settings, response)
                if settings_match is None:
                    logger.error(f"Failed to find settings URL for streamer {streamer.streamer_url}")
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                settings_url = settings_match.group(1)
                logger.info(f"Found settings URL for streamer {streamer.streamer_url}")

                settings_request = requests.get(settings_url, headers=headers)
                response = settings_request.text
                regex_spade = '"spade_url":"(.*?)"'
                spade_match = re.search(regex_spade, response)
                if spade_match is None:
                    logger.error(f"Failed to find spade URL in settings for streamer {streamer.streamer_url}" )
                    if attempt < max_retries - 1:  # Don't wait on the last attempt
                        time.sleep(delay)
                    continue
                streamer.stream.spade_url = spade_match.group(1)
                logger.info(
                    f"Found spade URL in settings for streamer {streamer.streamer_url}"
                )
                break  # Exit the loop if successful
            except requests.exceptions.RequestException as e:
                logger.error(f"Something went wrong during extraction of 'spade_url': {e}" )
                if attempt < max_retries - 1:  # Don't wait on the last attempt
                    time.sleep(delay)

perfect, that works, thanks

Rakambda commented 2 months ago

Replacing https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L142 with regex_settings = "(https://static.twitchcdn.net/config/settings.*?js|https://assets.twitch.tv/config/settings.*?.js)" should be enough.

5ji commented 2 months ago

Replacing

https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L142

with regex_settings = "(https://static.twitchcdn.net/config/settings.*?js|https://assets.twitch.tv/config/settings.*?.js)" should be enough.

Perfect. Succeed without retry.

howarder3 commented 2 months ago

Replacing

https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/3a9f030b01a3d5e842b2dc407bd56d3ca415e514/TwitchChannelPointsMiner/classes/Twitch.py#L142

with regex_settings = "(https://static.twitchcdn.net/config/settings.*?js|https://assets.twitch.tv/config/settings.*?.js)" should be enough.

Works perfect without retry, thanks!