Ubuntu の UFWでエラーがした
# ufw default deny Traceback (most recent call last): File "/usr/sbin/ufw", line 147, in <module> res = ui.do_action(pr.action, "", "", pr.force) File "/usr/lib/python3/dist-packages/ufw/frontend.py", line 648, in do_action res = self.set_default_policy(tmp[1], tmp[2]) File "/usr/lib/python3/dist-packages/ufw/frontend.py", line 239, in set_default_policy res = self.backend.set_default_policy(policy, direction) File "/usr/lib/python3/dist-packages/ufw/backend_iptables.py", line 135, in set_default_policy self.set_default(self.files['defaults'], \ File "/usr/lib/python3/dist-packages/ufw/backend.py", line 336, in set_default ufw.util.write_to_file(fd, line) File "/usr/lib/python3/dist-packages/ufw/util.py", line 256, in write_to_file rc = os.write(fd, bytes(out, 'ascii')) UnicodeEncodeError: 'ascii' codec can't encode characters in position 21-22: ordinal not in range(128)
解決策
/usr/lib/python3/dist-packages/ufw/util.py
253 rc = -1 254 # cover not in python3, so can't test for this 255 if sys.version_info[0] >= 3: # pragma: no cover 256 rc = os.write(fd, bytes(out, 'ascii')) 257 else: 258 rc = os.write(fd, out) 259
の256行目を
256 rc = os.write(fd, bytes(out, 'uft-8'))
とした。