# HG changeset patch # User jodogne # Date 1363083285 -3600 # Node ID 22bb88181e066eff9143fa0ca41ade5f4c089fb7 # Parent 4632a044746ebabb04a572d3bd2046384591683a credentials diff -r 4632a044746e -r 22bb88181e06 Resources/Samples/ImportDicomFiles/ImportDicomFiles.py --- a/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py Tue Feb 19 12:09:03 2013 +0100 +++ b/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py Tue Mar 12 11:14:45 2013 +0100 @@ -5,7 +5,7 @@ import os.path import httplib2 -if len(sys.argv) != 4: +if len(sys.argv) != 4 and len(sys.argv) != 6: print(""" Sample script to recursively import in Orthanc all the DICOM files that are stored in some path. Please make sure that Orthanc is running @@ -13,8 +13,9 @@ API. Usage: %s [hostname] [HTTP port] [path] +Usage: %s [hostname] [HTTP port] [path] [username] [password] For instance: %s localhost 8042 . -""" % (sys.argv[0], sys.argv[0])) +""" % (sys.argv[0], sys.argv[0], sys.argv[0])) exit(-1) URL = 'http://%s:%d/instances' % (sys.argv[1], int(sys.argv[2])) @@ -26,7 +27,7 @@ def UploadFile(path): global success - f = open(path, "r") + f = open(path, "rb") content = f.read() f.close() @@ -34,6 +35,10 @@ sys.stdout.write("Importing %s" % path) h = httplib2.Http() + + if len(sys.argv) == 6: + h.add_credentials(sys.argv[4], sys.argv[5]) + resp, content = h.request(URL, 'POST', body = content, headers = { 'content-type' : 'application/dicom' }) @@ -45,7 +50,7 @@ sys.stdout.write(" => failure (is it a DICOM file?)\n") except: - sys.stdout.write(" => unable to connect\n") + sys.stdout.write(" => unable to connect (is there a password?)\n") if os.path.isfile(sys.argv[3]):