changeset 370:22bb88181e06

credentials
author jodogne
date Tue, 12 Mar 2013 11:14:45 +0100
parents 4632a044746e
children cc0fe7890e89
files Resources/Samples/ImportDicomFiles/ImportDicomFiles.py
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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]):