changeset 4625:844ec5ecb6ef

Fix "OrthancServer/Resources/Samples/Python/Replicate.py" for Python 3.x
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Apr 2021 10:28:24 +0200
parents 926fa5ef8b4f
children 686f189a903d ee8706477b61
files NEWS OrthancServer/Resources/Samples/Python/Replicate.py
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Apr 15 11:29:40 2021 +0200
+++ b/NEWS	Mon Apr 19 10:28:24 2021 +0200
@@ -12,6 +12,7 @@
 -----------
 
 * Use the local timezone for query/retrieve in the Orthanc Explorer interface (was UTC before)
+* Fix "OrthancServer/Resources/Samples/Python/Replicate.py" for Python 3.x
 * Upgraded dependencies for static builds (notably on Windows and LSB):
   - civetweb 1.14
 
--- a/OrthancServer/Resources/Samples/Python/Replicate.py	Thu Apr 15 11:29:40 2021 +0200
+++ b/OrthancServer/Resources/Samples/Python/Replicate.py	Mon Apr 19 10:28:24 2021 +0200
@@ -51,7 +51,12 @@
         # Authentication (for some weird reason, this method does not
         # always work)
         # http://en.wikipedia.org/wiki/Basic_access_authentication
-        headers['authorization'] = 'Basic ' + base64.b64encode(username + ':' + password)
+
+        # The ".encode()" and ".decode()" below fix the following issue:
+        # https://groups.google.com/g/orthanc-users/c/KZ_iYOet5IQ/m/AUQWiSiAAQAJ
+        credentials = (username + ':' + password)
+        credentials_base64 = base64.b64encode(credentials.encode("ascii")).decode("ascii")
+        headers['authorization'] = 'Basic ' + credentials_base64
 
     return headers