# HG changeset patch # User Sebastien Jodogne # Date 1364209957 -3600 # Node ID 7000726bade70d23c1b18c6b52e09f17ae622231 # Parent cc0fe7890e8971a6d2ffa5077308e32386a0a89a fix ImportDicomFiles diff -r cc0fe7890e89 -r 7000726bade7 Resources/Samples/ImportDicomFiles/ImportDicomFiles.py --- 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]):