# HG changeset patch # User Sebastien Jodogne # Date 1717592163 -7200 # Node ID f85a7341b10388ec4015b4222576fb1ac7f285e7 # Parent 311835d686d9691532fbc16d02cfa5d246511090 upgrading SendStow.py and WadoRetrieveStudy.py sample scripts to Python 3 diff -r 311835d686d9 -r f85a7341b103 Resources/Samples/Python/SendStow.py --- a/Resources/Samples/Python/SendStow.py Wed Jun 05 14:37:09 2024 +0200 +++ b/Resources/Samples/Python/SendStow.py Wed Jun 05 14:56:03 2024 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Orthanc - A Lightweight, RESTful DICOM Store # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics diff -r 311835d686d9 -r f85a7341b103 Resources/Samples/Python/WadoRetrieveStudy.py --- a/Resources/Samples/Python/WadoRetrieveStudy.py Wed Jun 05 14:37:09 2024 +0200 +++ b/Resources/Samples/Python/WadoRetrieveStudy.py Wed Jun 05 14:56:03 2024 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Orthanc - A Lightweight, RESTful DICOM Store # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics @@ -22,7 +22,7 @@ import email -import urllib2 +import requests import sys if len(sys.argv) != 2: @@ -31,10 +31,16 @@ print('Example: %s http://localhost:8042/dicom-web/studies/1.3.51.0.1.1.192.168.29.133.1681753.1681732' % sys.argv[0]) sys.exit(-1) -answer = urllib2.urlopen(sys.argv[1]) -s = str(answer.info()) + "\n" + answer.read() +r = requests.get(sys.argv[1]) +r.raise_for_status() -msg = email.message_from_string(s) +headers = '' +for (key, value) in r.headers.items(): + headers += '%s: %s\n' % (key, value) + +s = bytes(headers + '\n', 'ascii') + r.content + +msg = email.message_from_bytes(s) for i, part in enumerate(msg.walk(), 1): filename = 'wado-%06d.dcm' % i @@ -42,4 +48,4 @@ if dicom != None: print('Storing DICOM file: %s' % filename) with open(filename, 'wb') as f: - f.write(str(dicom)) + f.write(dicom)