@@ -219,12 +219,14 @@ def call_nzbget_direct(url_command):
219
219
http_url = "http://%s:%s/jsonrpc/%s" % (HOST , PORT , url_command )
220
220
request = urllib .request .Request (http_url )
221
221
base_64_string = (
222
- base64 .b64encode (("%s:%s" % (USERNAME , PASSWORD )).encode ("utf-8" )).decode ("utf-8" ).strip ()
222
+ base64 .b64encode (("%s:%s" % (USERNAME , PASSWORD )).encode ("utf-8" ))
223
+ .decode ("utf-8" )
224
+ .strip ()
223
225
)
224
226
request .add_header ("Authorization" , "Basic %s" % base_64_string )
225
227
response = urllib .request .urlopen (request ) # get some data from NZBGet
226
228
# data is a JSON raw-string, contains ALL properties each NZB in queue
227
- data = response .read ().decode (' utf-8' )
229
+ data = response .read ().decode (" utf-8" )
228
230
return data
229
231
230
232
@@ -1041,7 +1043,9 @@ def get_server_settings(nzb_age):
1041
1043
return servers
1042
1044
1043
1045
1044
- def create_sockets (server , articles_to_check ) -> Tuple [list [ssl .SSLSocket ], list [int ], int ]:
1046
+ def create_sockets (
1047
+ server , articles_to_check
1048
+ ) -> Tuple [list [ssl .SSLSocket ], list [int ], int ]:
1045
1049
"""
1046
1050
create the sockets for the server that will be used to send in
1047
1051
check_send_server_reply() and receive in check_failure_status()
@@ -1213,6 +1217,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1213
1217
socket_loop_count = [- 1 ] * num_conn
1214
1218
failed_wait_count = 0
1215
1219
loop_fail = False
1220
+ chunk = 4096
1216
1221
start_time = time .time ()
1217
1222
print ("Using server: " + host )
1218
1223
sys .stdout .flush ()
@@ -1253,13 +1258,11 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1253
1258
if send_articles > articles_to_check - 1 :
1254
1259
break
1255
1260
try :
1256
-
1257
- data = sockets [i ].recv (4096 )
1258
- reply = data .read ().decode ("utf-8" )
1259
- print ('DETAIL ___REPLY___' , str (reply ))
1261
+ data = sockets [i ].recv (chunk )
1262
+ reply = ""
1260
1263
while data :
1261
- data = sockets [ i ]. recv ( 4096 )
1262
- reply += data . read (). decode ( "utf-8" )
1264
+ reply += data . decode ( "utf-8" )
1265
+ data = sockets [ i ]. recv ( chunk )
1263
1266
except : # each error would trigger the same effect
1264
1267
# avoid continuous looping on fast machines by adding delays
1265
1268
# EAGAIN, EWOULDBLOCK, ssl.SSLWantReadError
@@ -1319,7 +1322,9 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1319
1322
+ " marking requested article as failed."
1320
1323
)
1321
1324
sys .stdout .flush ()
1322
- reply = "999 Article marked as failed by script." .encode (encoding = "utf-8" )
1325
+ reply = "999 Article marked as failed by script." .encode (
1326
+ encoding = "utf-8"
1327
+ )
1323
1328
failed_wait_count += 1
1324
1329
if failed_wait_count >= 20 :
1325
1330
print (
@@ -1412,12 +1417,11 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1412
1417
for i in socket_list [m :]: # loop through ok sockets
1413
1418
reply = None
1414
1419
try :
1415
- data = sockets [i ].recv (4096 )
1416
- reply = data .read ().decode ("utf-8" )
1417
- print ('DETAIL ___REPLY___' , str (reply ))
1420
+ data = sockets [i ].recv (chunk )
1421
+ reply = ""
1418
1422
while data :
1419
- data = sockets [ i ]. recv ( 4096 )
1420
- reply += data . read (). decode ( "utf-8" )
1423
+ reply += data . decode ( "utf-8" )
1424
+ data = sockets [ i ]. recv ( chunk )
1421
1425
except : # managing all socket errors
1422
1426
err = sys .exc_info ()
1423
1427
if socket_loop_count [i ] < 5 :
0 commit comments