From af6b149894dea89ee2fc7aa101d07ef6682470e8 Mon Sep 17 00:00:00 2001 From: javanesse Date: Tue, 9 Apr 2019 05:25:23 +0900 Subject: [PATCH] Adapted to Phyton V3 In phyton 3, the xrange was changed to range. its mean xrange=range also The solution to "TypeError: write() argument must be str, not bytes" error when saving a downloaded page to file is adding a "b" letter for binary --- takeAndGet.py => TakeAndGet-Py3.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) rename takeAndGet.py => TakeAndGet-Py3.py (79%) diff --git a/takeAndGet.py b/TakeAndGet-Py3.py similarity index 79% rename from takeAndGet.py rename to TakeAndGet-Py3.py index 1ee9a4a..3defc1e 100644 --- a/takeAndGet.py +++ b/TakeAndGet-Py3.py @@ -57,6 +57,25 @@ # WAIT FOR LAST IMAGE TO CHANGE +# IF YOU ARE USING PYTHON V.2 +""" +sys.stdout.write('Waiting for image processing') +sys.stdout.flush() + +for x in range(1, 30): + sys.stdout.write('.') + sys.stdout.flush() + data = {"id": pictureId } + resp = requests.post(BASEURL + 'commands/status', json=data) + if format(resp.json()["state"])=='done': + break + time.sleep(0.5) + +print ('') +uri = resp.json()["results"]["fileUri"] +#print ('uri: {}'.format(uri)) +""" + sys.stdout.write('Waiting for image processing') sys.stdout.flush() @@ -89,6 +108,8 @@ # SAVE NEW IMAGE +# IF YOU ARE USING PYTHON V.2 +""" resp.raw.decode_content = True with open(name,'w') as ofh: @@ -96,6 +117,15 @@ ofh.write(chunk) print ('Image stored as: {}'.format(name)) +""" + +resp.raw.decode_content = True + +with open(name,'wb') as ofh: + for chunk in resp: + ofh.write(chunk) + +print ('Image stored as: {}'.format(name))