diff options
author | Vilém Duha <vilda.novak@gmail.com> | 2019-09-02 14:50:06 +0300 |
---|---|---|
committer | Vilém Duha <vilda.novak@gmail.com> | 2019-09-02 14:50:06 +0300 |
commit | db4f7e2dc66d437b205f8097c2bdf9097b5c8834 (patch) | |
tree | f5657def06ae9fe5298c9f17fca164635662de96 /blenderkit/download.py | |
parent | e529809cf6513748776a878338109ecf960d1326 (diff) |
BlenderKit: rerequests library
this library basically ensures that no server requests should fail if the token is after it's lifetime.
it refreshes token and re-tries the request in such cases.
Diffstat (limited to 'blenderkit/download.py')
-rw-r--r-- | blenderkit/download.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/blenderkit/download.py b/blenderkit/download.py index 366081ca..9f5f0314 100644 --- a/blenderkit/download.py +++ b/blenderkit/download.py @@ -25,8 +25,9 @@ if "bpy" in locals(): ui = reload(ui) colors = reload(colors) tasks_queue = reload(tasks_queue) + rerequests = reload(rerequests) else: - from blenderkit import paths, append_link, utils, ui, colors, tasks_queue + from blenderkit import paths, append_link, utils, ui, colors, tasks_queue, rerequests import threading import time @@ -266,7 +267,7 @@ def report_usages(): scene['assets rated'][k] = scene['assets rated'].get(k, False) thread = threading.Thread(target=utils.requests_post_thread, args=(url, usage_report, headers)) thread.start() - # r = requests.post(url, headers=headers, json=usage_report) + # r = rerequests.post(url, headers=headers, json=usage_report) mt = time.time() - mt print('report generation: ', mt) @@ -551,6 +552,7 @@ class Downloader(threading.Thread): tcom.downloaded = 100 utils.p('not downloading, trying to append again') return; + file_name = paths.get_download_filenames(asset_data)[0] # prefer global dir if possible. # for k in asset_data: # print(asset_data[k]) @@ -617,7 +619,6 @@ def download(asset_data, **kwargs): asset_data = copy.deepcopy(asset_data) else: asset_data = asset_data.to_dict() - readthread = Downloader(asset_data, tcom, scene_id, api_key) readthread.start() @@ -730,7 +731,7 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None): } r = None try: - r = requests.get(asset_data['download_url'], params=data, headers=headers) + r = rerequests.get(asset_data['download_url'], params=data, headers=headers) except Exception as e: print(e) if tcom is not None: @@ -755,10 +756,6 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None): tasks_queue.add_task((ui.add_report, (r1, 5, colors.RED))) tcom.error = True - if r.status_code == 401: - tcom.report = 'Invalid API key' - tcom.error = True - return 'Invalid API key' elif r.status_code >= 500: tcom.report = 'Server error' tcom.error = True @@ -833,7 +830,6 @@ class BlenderkitDownloadOperator(bpy.types.Operator): bl_label = "BlenderKit Asset Download" bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} - asset_type: EnumProperty( name="Type", items=asset_types, |