Mercurial > hg > orthanc
changeset 373:7000726bade7
fix ImportDicomFiles
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 25 Mar 2013 12:12:37 +0100 |
parents | cc0fe7890e89 |
children | 42e87c17cab8 |
files | Resources/Samples/ImportDicomFiles/ImportDicomFiles.py |
diffstat | 1 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py Tue Mar 12 11:21:03 2013 +0100 +++ b/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py Mon Mar 25 12:12:37 2013 +0100 @@ -4,6 +4,7 @@ import sys import os.path import httplib2 +import base64 if len(sys.argv) != 4 and len(sys.argv) != 6: print(""" @@ -36,21 +37,33 @@ h = httplib2.Http() + headers = { 'content-type' : 'application/dicom' } + if len(sys.argv) == 6: - h.add_credentials(sys.argv[4], sys.argv[5]) - + username = sys.argv[4] + password = sys.argv[5] + + # h.add_credentials(username, password) + + # This is a custom reimplementation of the + # "Http.add_credentials()" method for Basic HTTP Access + # 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) + resp, content = h.request(URL, 'POST', body = content, - headers = { 'content-type' : 'application/dicom' }) + headers = headers) if resp.status == 200: sys.stdout.write(" => success\n") success += 1 else: - sys.stdout.write(" => failure (is it a DICOM file?)\n") + sys.stdout.write(" => failure (Is it a DICOM file?)\n") except: - sys.stdout.write(" => unable to connect (is there a password?)\n") + sys.stdout.write(" => unable to connect (Is Orthanc running? Is there a password?)\n") if os.path.isfile(sys.argv[3]):