Skip to content

Commit 065002f

Browse files
committed
Fix "http" service plugin on Python 3
If "srv.SCRIPTNAME" was None, the plugin croaked on Python 3 with "expected string or bytes-like object".
1 parent c8d10f4 commit 065002f

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ in progress
77
===========
88

99
- Rename repository default branch to "main"
10+
- Fix "http" service plugin
1011

1112
2021-06-12 0.24.0
1213
=================

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ coverage:
55
status:
66
project:
77
default:
8-
#target: 85% # the required coverage value
8+
target: 14% # the required coverage value
99
threshold: 3% # the leniency in hitting the target

mqttwarn/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ def bootstrap(config=None, scriptname=None):
708708
invoker = FunctionInvoker(config=config, srv=make_service(mqttc=None, name='mqttwarn.context'))
709709
context = RuntimeContext(config=config, invoker=invoker)
710710
cf = config
711-
SCRIPTNAME = scriptname
711+
if scriptname is not None:
712+
SCRIPTNAME = scriptname
712713

713714

714715
def run_plugin(config=None, name=None, data=None):

mqttwarn/services/http_urllib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ def plugin(srv, item):
7575
resource = url
7676

7777
request = urllib.request.Request(resource)
78-
request.add_header('User-agent', srv.SCRIPTNAME)
7978

79+
if srv.SCRIPTNAME is not None:
80+
request.add_header('User-agent', srv.SCRIPTNAME)
8081
if auth is not None:
8182
request.add_header("Authorization", "Basic %s" % auth)
8283

@@ -107,9 +108,12 @@ def plugin(srv, item):
107108

108109

109110
request.data = encoded_params.encode('utf-8')
110-
request.add_header('User-agent', srv.SCRIPTNAME)
111+
112+
if srv.SCRIPTNAME is not None:
113+
request.add_header('User-agent', srv.SCRIPTNAME)
111114
if auth is not None:
112115
request.add_header("Authorization", "Basic %s" % auth)
116+
113117
srv.logging.debug("before send")
114118
resp = urllib.request.urlopen(request, timeout=timeout)
115119
data = resp.read()

0 commit comments

Comments
 (0)