write need bytes object on python 3 (#35143)

Otherwise, it fail with:

    Traceback (most recent call last):
      File \"/tmp/ansible_c1zmq3i9/ansible_module_openssl_certificate.py\", line 808, in <module>
        main()
      File \"/tmp/ansible_c1zmq3i9/ansible_module_openssl_certificate.py\", line 787, in main
        certificate.generate(module)
      File \"/tmp/ansible_c1zmq3i9/ansible_module_openssl_certificate.py\", line 692, in generate
        certfile.write(str(crt))
    TypeError: a bytes-like object is required, not 'str'
This commit is contained in:
Michael Scherer 2018-01-21 12:26:32 +01:00 committed by ansibot
parent f23f277e46
commit 347b5d1e50

View file

@ -757,7 +757,7 @@ class AcmeCertificate(Certificate):
self.challenge_path), self.challenge_path),
check_rc=True)[1] check_rc=True)[1]
with open(self.path, 'wb') as certfile: with open(self.path, 'wb') as certfile:
certfile.write(str(crt)) certfile.write(to_bytes(crt))
except OSError as exc: except OSError as exc:
raise CertificateError(exc) raise CertificateError(exc)