Blob Blame History Raw
From 14765fca34efb80598463aba49a48758ffca598c Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Mon, 27 Jul 2020 10:09:43 +0200
Subject: [PATCH] azure-events: import URLError in Python 3+ and encode
 postData when necessary

---
 heartbeat/azure-events.in | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
index d4a166d9f..4eed376fb 100644
--- a/heartbeat/azure-events.in
+++ b/heartbeat/azure-events.in
@@ -15,6 +15,7 @@ try:
 		import urllib2
 except ImportError:
 		import urllib.request as urllib2
+		from urllib.error import URLError
 import socket
 from collections import defaultdict
 
@@ -79,6 +80,9 @@ class azHelper:
 		ocf.logger.debug("_sendMetadataRequest: begin; endpoint = %s, postData = %s" % (endpoint, postData))
 		ocf.logger.debug("_sendMetadataRequest: url = %s" % url)
 
+		if postData and type(postData) != bytes:
+			postData = postData.encode()
+
 		req = urllib2.Request(url, postData)
 		req.add_header("Metadata", "true")
 		req.add_header("User-Agent", USER_AGENT)