# XNAT download\_dir called in a slicer module does not work as expected on fetching some of images, while exactly the same code works fine when run outside slicer

**URL:** <https://discourse.slicer.org/t/xnat-download-dir-called-in-a-slicer-module-does-not-work-as-expected-on-fetching-some-of-images-while-exactly-the-same-code-works-fine-when-run-outside-slicer/27350>\
**Category:** Development\
**Tags:** dicom\
**Created:** [January 19, 2023, 12:55pm UTC](https://discourse.slicer.org/t/xnat-download-dir-called-in-a-slicer-module-does-not-work-as-expected-on-fetching-some-of-images-while-exactly-the-same-code-works-fine-when-run-outside-slicer/27350 "2023-01-19T12:55:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [January 19, 2023, 12:55pm UTC](https://discourse.slicer.org/t/xnat-download-dir-called-in-a-slicer-module-does-not-work-as-expected-on-fetching-some-of-images-while-exactly-the-same-code-works-fine-when-run-outside-slicer/27350/1 "2023-01-19T12:55:33Z")

</div>

Hello,

In one module I’d developed functionality to connect to RIA database through XNAT api and download specific images to local. Unfortunately I learned that for some unknown reason to me it drops on download\_dir. I tried a lot to find the issue and after a lot investigations I know that the same exact code that I’m running in slicer works perfectly if I run it outside slicer.  
the code is as simple as:

```auto
import xnat
username=#username
password=#password
ria = xnat.connect('http://ria.ds.umcutrecht.nl/', user=username, password=password)
...
try:
   scan.resources["DICOM"].download_dir(temp_download_dir+"\\")
except:
   print("could not download!")

```

basically the error is something that I never get running the code outside slicer, something like this:

```auto
    scan.resources["DICOM"].download_dir(
  File "C:\Users\saeed\AppData\Local\NA-MIC\Slicer 5.0.2\lib\Python\Lib\site-packages\xnat\mixin.py", line 591, in download_dir
    zip_file.extractall(target_dir)
  File "C:\Users\saeed\AppData\Local\NA-MIC\Slicer 5.0.2\lib\Python\Lib\zipfile.py", line 1633, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "C:\Users\saeed\AppData\Local\NA-MIC\Slicer 5.0.2\lib\Python\Lib\zipfile.py", line 1687, in _extract_member
    open(targetpath, "wb") as target:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\saeed\\Desktop\\tmp2\\00-ria\\02-026\\02-026_212596038910566_662398200_20210301\\302\\DICOM\\temp\\02-026_212596038910566_662398200_20210301\\scans\\302-MPR_SAG_3D_PD_SPAIR\\resources\\DICOM\\files\\1.3.46.670589.50.2.15757877403410526784.31298281802920234632-302-43-687f92.dcm'

```

I was wondering is there any thoughts why this is happening?

Best,  
Saeed
