Page 2 of 2

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

Posted: June 5th, 2020, 5:59 pm
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?

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

Posted: June 5th, 2020, 6:18 pm
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.

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

Posted: June 5th, 2020, 7:31 pm
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.

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

Posted: June 5th, 2020, 7:37 pm
by sander
Good that it works.

Pity you cleaned the log files: I was very curious what Warning print would say.

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

Posted: June 8th, 2020, 5:54 am
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).

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

Posted: October 13th, 2020, 9:01 am
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'

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

Posted: October 13th, 2020, 9:16 am
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.

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

Posted: November 27th, 2020, 12:34 pm
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'

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

Posted: November 28th, 2020, 12:11 am
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 ... ?

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

Posted: November 28th, 2020, 8:59 am
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.