Skip to content

Commit d34d164

Browse files
author
Ilya Ableev
committed
#71, fixed Python3 compatibility
1 parent b330fbf commit d34d164

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

zbxtg.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ def graph_get(self, itemid, period, title, width, height, version=3):
344344
print_message("can't get image from '{0}'".format(zbx_img_url))
345345
return False
346346
res_img = answer.content
347-
with open(file_img, 'wb') as fp:
348-
fp.write(res_img)
347+
file_bwrite(file_img, res_img)
349348
return file_img
350349

351350
def api_test(self):
@@ -417,6 +416,12 @@ def file_write(filename, text):
417416
return True
418417

419418

419+
def file_bwrite(filename, data):
420+
with open(filename, "wb") as fd:
421+
fd.write(data)
422+
return True
423+
424+
420425
def file_read(filename):
421426
with open(filename, "r") as fd:
422427
text = fd.readlines()
@@ -431,10 +436,10 @@ def file_append(filename, text):
431436

432437
def external_image_get(url, tmp_dir, timeout=6):
433438
image_hash = hashlib.md5()
434-
image_hash.update(url)
439+
image_hash.update(url.encode())
435440
file_img = tmp_dir + "/external_{0}.png".format(image_hash.hexdigest())
436441
try:
437-
answer = requests.get(url, timeout=timeout)
442+
answer = requests.get(url, timeout=timeout, allow_redirects=True)
438443
except requests.exceptions.ReadTimeout as ex:
439444
print_message("Can't get external image from '{0}': timeout".format(url))
440445
return False
@@ -443,7 +448,7 @@ def external_image_get(url, tmp_dir, timeout=6):
443448
print_message("Can't get external image from '{0}': HTTP 404 error".format(url))
444449
return False
445450
answer_image = answer.content
446-
file_write(file_img, answer_image)
451+
file_bwrite(file_img, answer_image)
447452
return file_img
448453

449454

0 commit comments

Comments
 (0)