fix python3 show error :'str' object has no attribute 'decode'

This commit is contained in:
yujunfeng 2020-01-15 15:32:40 +08:00
parent 2363a00550
commit 9850158401
1 changed files with 7 additions and 2 deletions

View File

@ -23,7 +23,8 @@ from scp import SCPClient
from tqdm import tqdm from tqdm import tqdm
import traceback import traceback
if sys.version_info[0] < 3: IS_PY2 = sys.version_info[0] < 3
if IS_PY2:
reload(sys) reload(sys)
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
@ -96,7 +97,11 @@ def on_message(message, data):
last_sent = [0] last_sent = [0]
def progress(filename, size, sent): def progress(filename, size, sent):
t.desc = os.path.basename(filename).decode("utf-8") baseName = os.path.basename(filename)
if IS_PY2:
t.desc = baseName.decode("utf-8")
else:
t.desc = baseName
t.total = size t.total = size
t.update(sent - last_sent[0]) t.update(sent - last_sent[0])
last_sent[0] = 0 if size == sent else sent last_sent[0] = 0 if size == sent else sent