You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upon receiving a webhook of default templating from Netbox v3.1.7, the following error is generated otherwise causing silent failure, on a fresh install.
The request data returned by request.get_data() appears to now be returning the request body encoded for UTF-8 by default, possibly as a new behavior of flask.
While I was not able to track down this exact behavior whilst skimming Flask's changelogs, I did find that they had done a lot of deprecation and other work with request JSON encoding/decoding. Referring to the documentation, https://tedboy.github.io/flask/generated/generated/flask.Request.get_data.html mentions an as_text flag for the function request.get_data(), saying this:
If as_text is set to True the return value will be a decoded unicode string
Amending the flag to the request.get_data() invocation parameters at line 34 of sensors/netbox_webhooks.py to become request.get_data(as_text=True) appears to mitigate the issue. This has been tested in production staging and appears to resolve it. Will be opening a PR to address this issue promptly.
2022-03-14 20:13:04,333 139891243266120 INFO _internal [-] 1.1.1.1 - - [14/Mar/2022 20:13:04] "ESC[35mESC[1mPOST /netbox/webhooks
/ HTTP/1.1ESC[0m" 500 -
2022-03-14 20:14:12,302 139891243266120 ERROR app [-] Exception on /netbox/webhooks/ [POST]
Traceback (most recent call last):
File "/opt/stackstorm/virtualenvs/netbox/lib/python3.6/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/opt/stackstorm/virtualenvs/netbox/lib/python3.6/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/stackstorm/virtualenvs/netbox/lib/python3.6/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/stackstorm/virtualenvs/netbox/lib/python3.6/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/opt/stackstorm/packs/netbox/sensors/netbox_webhooks.py", line 34, in event
msg=request.get_data().encode('utf8'),
AttributeError: 'bytes' object has no attribute 'encode'
The text was updated successfully, but these errors were encountered:
Alternatively, request.get_data().encode('utf8') could just become request.get_data() instead of request.get_data(as_text=True).encode('utf8'), assuming get_data()is and always will return UTF-8 encoded bytestrings when no flags are specified.
This determination would require more familiarity with Flask than I have, I know for a fact as_text=True yields the expected behavior but don't know Flask well enough to determine whether this is the proper fix.
Upon receiving a webhook of default templating from Netbox v3.1.7, the following error is generated otherwise causing silent failure, on a fresh install.
The request data returned by
request.get_data()
appears to now be returning the request body encoded for UTF-8 by default, possibly as a new behavior of flask.While I was not able to track down this exact behavior whilst skimming Flask's changelogs, I did find that they had done a lot of deprecation and other work with request JSON encoding/decoding. Referring to the documentation, https://tedboy.github.io/flask/generated/generated/flask.Request.get_data.html mentions an
as_text
flag for the functionrequest.get_data()
, saying this:Amending the flag to the
request.get_data()
invocation parameters at line 34 ofsensors/netbox_webhooks.py
to becomerequest.get_data(as_text=True)
appears to mitigate the issue. This has been tested inproductionstaging and appears to resolve it. Will be opening a PR to address this issue promptly.The text was updated successfully, but these errors were encountered: