Automatically export .dcm study when uploaded to Orthanc

Hi,

I need assistance with automatically exporting studies when sent to Orthanc in .dcm format into a local folder.

Hello,

You are most likely looking for the “AutoClassify.py” sample script in the Orthanc source distribution:
https://hg.orthanc-server.com/orthanc/file/tip/OrthancServer/Resources/Samples/Python/AutoClassify.py

Also have a look at WebDAV built-in support:
https://book.orthanc-server.com/users/webdav.html

Regards,
Sébastien-

Hi Sébastien,

Thank you for your feedback.

I am a complete newbie with Python.

Please can you guide me with the following error:

python3 export.py
Traceback (most recent call last):
File “export.py”, line 54, in
import RestToolbox
File “/home/admin365/RestToolbox.py”, line 3, in
from urllib import urlencode
ImportError: cannot import name ‘urlencode’ from ‘urllib’ (/usr/lib/python3.8/urllib/init.py)

That might be related to your Python Version ?

I think it is different in 2 vs. 3 ? Maybe try that.

Python 2:

from urllib import urlencode

Python 3:

from urllib.parse import urlencode

/sds

You are visibly using an extremely old version of the file “RestToolbox.py”. Support for Python 3 was added back in 2014 through this changeset (that was part of Orthanc 0.8.5):
https://hg.orthanc-server.com/orthanc/rev/4e9d517503ae

Use the link I provided you above to get up-to-date sample scripts:

https://hg.orthanc-server.com/orthanc/file/default/OrthancServer/Resources/Samples/Python/

Sébastien-

Hi,

Thank you for the update link.

Updated accordingly and get the following:

Traceback (most recent call last):
File “export.py”, line 193, in
current = RestToolbox.DoGet(URL + ‘/changes?last’)[‘Last’]
File “/home/admin365/RestToolbox.py”, line 54, in DoGet
raise Exception(resp.status)
Exception: 401

The 401 HTTP status code means “Unauthorized”:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401

Either you haven’t allowed remote connections to Orthanc, or you have to call “RestToolbox.SetCredentials()” in the Python script.

Sébastien-