Mercurial > hg > orthanc
comparison Resources/Samples/ImportDicomFiles/ImportDicomFiles.py @ 3817:37e20bbf25f5
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 08 Apr 2020 14:50:06 +0200 |
parents | c81ac6ff232b |
children |
comparison
equal
deleted
inserted
replaced
3816:09f091b6b569 | 3817:37e20bbf25f5 |
---|---|
70 # This is a custom reimplementation of the | 70 # This is a custom reimplementation of the |
71 # "Http.add_credentials()" method for Basic HTTP Access | 71 # "Http.add_credentials()" method for Basic HTTP Access |
72 # Authentication (for some weird reason, this method does | 72 # Authentication (for some weird reason, this method does |
73 # not always work) | 73 # not always work) |
74 # http://en.wikipedia.org/wiki/Basic_access_authentication | 74 # http://en.wikipedia.org/wiki/Basic_access_authentication |
75 headers['authorization'] = 'Basic ' + base64.b64encode(username + ':' + password) | 75 creds_str = username + ':' + password |
76 creds_str_bytes = creds_str.encode("ascii") | |
77 creds_str_bytes_b64 = b'Basic ' + base64.b64encode(creds_str_bytes) | |
78 headers['authorization'] = creds_str_bytes_b64.decode("ascii") | |
76 | 79 |
77 resp, content = h.request(URL, 'POST', | 80 resp, content = h.request(URL, 'POST', |
78 body = content, | 81 body = content, |
79 headers = headers) | 82 headers = headers) |
80 | 83 |
83 success_count += 1 | 86 success_count += 1 |
84 else: | 87 else: |
85 sys.stdout.write(" => failure (Is it a DICOM file? Is there a password?)\n") | 88 sys.stdout.write(" => failure (Is it a DICOM file? Is there a password?)\n") |
86 | 89 |
87 except: | 90 except: |
91 type, value, traceback = sys.exc_info() | |
92 sys.stderr.write(str(value)) | |
88 sys.stdout.write(" => unable to connect (Is Orthanc running? Is there a password?)\n") | 93 sys.stdout.write(" => unable to connect (Is Orthanc running? Is there a password?)\n") |
89 | 94 |
90 | 95 |
91 if os.path.isfile(sys.argv[3]): | 96 if os.path.isfile(sys.argv[3]): |
92 # Upload a single file | 97 # Upload a single file |