comparison Resources/Samples/ImportDicomFiles/ImportDicomFiles.py @ 373:7000726bade7

fix ImportDicomFiles
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 25 Mar 2013 12:12:37 +0100
parents 22bb88181e06
children 29982cfc5009
comparison
equal deleted inserted replaced
372:cc0fe7890e89 373:7000726bade7
2 2
3 import os 3 import os
4 import sys 4 import sys
5 import os.path 5 import os.path
6 import httplib2 6 import httplib2
7 import base64
7 8
8 if len(sys.argv) != 4 and len(sys.argv) != 6: 9 if len(sys.argv) != 4 and len(sys.argv) != 6:
9 print(""" 10 print("""
10 Sample script to recursively import in Orthanc all the DICOM files 11 Sample script to recursively import in Orthanc all the DICOM files
11 that are stored in some path. Please make sure that Orthanc is running 12 that are stored in some path. Please make sure that Orthanc is running
34 try: 35 try:
35 sys.stdout.write("Importing %s" % path) 36 sys.stdout.write("Importing %s" % path)
36 37
37 h = httplib2.Http() 38 h = httplib2.Http()
38 39
40 headers = { 'content-type' : 'application/dicom' }
41
39 if len(sys.argv) == 6: 42 if len(sys.argv) == 6:
40 h.add_credentials(sys.argv[4], sys.argv[5]) 43 username = sys.argv[4]
41 44 password = sys.argv[5]
45
46 # h.add_credentials(username, password)
47
48 # This is a custom reimplementation of the
49 # "Http.add_credentials()" method for Basic HTTP Access
50 # Authentication (for some weird reason, this method does
51 # not always work)
52 # http://en.wikipedia.org/wiki/Basic_access_authentication
53 headers['authorization'] = 'Basic ' + base64.b64encode(username + ':' + password)
54
42 resp, content = h.request(URL, 'POST', 55 resp, content = h.request(URL, 'POST',
43 body = content, 56 body = content,
44 headers = { 'content-type' : 'application/dicom' }) 57 headers = headers)
45 58
46 if resp.status == 200: 59 if resp.status == 200:
47 sys.stdout.write(" => success\n") 60 sys.stdout.write(" => success\n")
48 success += 1 61 success += 1
49 else: 62 else:
50 sys.stdout.write(" => failure (is it a DICOM file?)\n") 63 sys.stdout.write(" => failure (Is it a DICOM file?)\n")
51 64
52 except: 65 except:
53 sys.stdout.write(" => unable to connect (is there a password?)\n") 66 sys.stdout.write(" => unable to connect (Is Orthanc running? Is there a password?)\n")
54 67
55 68
56 if os.path.isfile(sys.argv[3]): 69 if os.path.isfile(sys.argv[3]):
57 # Upload a single file 70 # Upload a single file
58 UploadFile(sys.argv[3]) 71 UploadFile(sys.argv[3])