Sabnzbd keeps crashing TypeError: can't concat int to bytes

Questions and bug reports for Beta releases should be posted here.
Forum rules
Help us help you:
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
ash7777
Newbie
Newbie
Posts: 12
Joined: August 8th, 2019, 6:08 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by ash7777 »

Thanks! It's working much better now.

I'm mystified by something. If I understand correctly, these lines:

Code: Select all

        try:
            self.servercount[serverid] += bytes
        except KeyError:
            # Not yet known, so initialize:
            self.servercount[serverid] = bytes
are functionally equivalent to these lines (which are the original code):

Code: Select all

        if serverid in self.servercount:
            self.servercount[serverid] += bytes
        else:
            self.servercount[serverid] = bytes
and these lines work around the problem I was having:

Code: Select all

        except Exception as e:
            # could not add int, so reset
            logging.warning("Non-int value in self.servercount[serverid]: %s", self.servercount[serverid])
            self.servercount[serverid] = bytes
which implies I should be seeing log entries that say "Non-int value in ..." and I'm not seeing any such lines. Does that surprise you?
User avatar
sander
Release Testers
Release Testers
Posts: 8812
Joined: January 22nd, 2008, 2:22 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by sander »

"much better"? Not 100% good?

"I'm not seeing any such lines. Does that surprise you?" Yes, that does surprise me: I would expect it once.
ash7777
Newbie
Newbie
Posts: 12
Joined: August 8th, 2019, 6:08 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by ash7777 »

Sorry, I tend to understate. It's been running for about an hour and everything seems completely normal.

It is possible the message was logged once. I cleaned the log files at shortly after applying the fix.
User avatar
sander
Release Testers
Release Testers
Posts: 8812
Joined: January 22nd, 2008, 2:22 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by sander »

Good that it works.

Pity you cleaned the log files: I was very curious what Warning print would say.
User avatar
sander
Release Testers
Release Testers
Posts: 8812
Joined: January 22nd, 2008, 2:22 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by sander »

ash7777

safihre has changed the code in a much better way (https://github.com/sabnzbd/sabnzbd/comm ... 27c7c36a27 specifcally https://github.com/sabnzbd/sabnzbd/comm ... cL775-R777 ), hopefully removing the root cause of your problem.
That means that with the next release, which you will receive via the Ubuntu jcfp PPA (so beta3, or anything higher than beta2), the problem should not occur anymore (and my workaround is not necesary anymore).
ash7777
Newbie
Newbie
Posts: 12
Joined: August 8th, 2019, 6:08 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by ash7777 »

I haven't upgraded since this happened, and it occurred again yesterday.

The log message was:

Code: Select all

 Non-int value in self.servercount[serverid]: b'220'
User avatar
sander
Release Testers
Release Testers
Posts: 8812
Joined: January 22nd, 2008, 2:22 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by sander »

ash7777 wrote: October 13th, 2020, 9:01 am I haven't upgraded since this happened
Upgrade! There were a lot of improvements and releases since June 2020.
nohbdy
Newbie
Newbie
Posts: 2
Joined: November 27th, 2020, 12:21 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by nohbdy »

Google has led me here as I am having the same issue in version 3.1.1.

Happy to help debug. I notice the affected code has changed somewhat (notably, renaming the "bytes" variable to "bytes_received"

Current error:

Exception in thread Thread-1:
Traceback (most recent call last):
File "[DEFEATING_URL_DETECTION_REMOVED_PATH]threading[.]py", line 932, in _bootstrap_inner
self[.]run()
File "[DEFEATING_URL_DETECTION_REMOVED_PATH]downloader[.]py", line 637, in run
nzo[.]update_download_stats(BPSMeter[.]do[.]bps, server[.]id, bytes_received)
File "[DEFEATING_URL_DETECTION_REMOVED_PATH]nzbstuff[.]py", line 924, in update_download_stats
self.servercount[serverid] += bytes_received
TypeError: can't concat int to bytes

Based on the previous posts in this thread, I changed the code slightly:

try:
self.servercount[serverid] += bytes_received
except KeyError:
# Not yet known, so initialize:
self.servercount[serverid] = bytes_received
except Exception as e:
# could not add int, so reset
logging.warning("Non-int value in self.servercount[serverid]: %s", self.servercount[serverid])
self.servercount[serverid] = bytes_received

# if serverid in self.servercount:
# self.servercount[serverid] += bytes_received
# else:
# self.servercount[serverid] = bytes_received

This now produces the following warning:

Non-int value in self.servercount[serverid]: b'222'
User avatar
sander
Release Testers
Release Testers
Posts: 8812
Joined: January 22nd, 2008, 2:22 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by sander »

nice try-except and logging.

can you keep it runnning for some time, and post the logging.warning's here? Always the same, or ... ?
nohbdy
Newbie
Newbie
Posts: 2
Joined: November 27th, 2020, 12:21 pm

Re: Sabnzbd keeps crashing TypeError: can't concat int to bytes

Post by nohbdy »

sander wrote: November 28th, 2020, 12:11 am nice try-except and logging.

can you keep it runnning for some time, and post the logging.warning's here? Always the same, or ... ?
No other warnings. Tried restarting and executing a few downloads and never got another warning. So, just the one.

Without actually tracing the code, I guess when this set in the except block: self.servercount[serverid] = bytes_received, the corresponding value is eventually overwritten in a persistent file somewhere on disk. Thus the error doesn't occur again.
Post Reply