templateflow / python-client

A python client to query TemplateFlow via pyBIDS
https://templateflow.org/python-client/
Apache License 2.0
8 stars 10 forks source link

Templates not loaded on Windows #89

Closed ChristianNSchmitz closed 8 months ago

ChristianNSchmitz commented 2 years ago

Hello, we are using the templateflow python-client both on a Windows and Linux environment (WSL system) using anaconda with python 3.9. Whereas the WSL system loads the templates just fine, the templates are not loaded on the Windows environment (similar to https://github.com/templateflow/tpl-MNI152NLin2009cAsym/issues/6). Initially, I thought this might be due to an erroneous SSL certificate (oftentimes the reason for issues at our institute), but both systems use the identical certificate. I tried both with and without the datalad option. Thus, I would like to ask you whether there could be a problem with the windows system. If you need any other information, please let me know! Thanks a lot! Christian

oesteban commented 2 years ago

We will need further information to understand the problem. What templates are affected? In all the cases was the download successful for Linux but wasn't for Windows?

mfschmidt commented 1 year ago

I think I can provide the necessary details here. I usually use linux without issue, but was trying to hack at a script in Windows and ran into this issue. It also popped up on neurostars. I was going to respond to that, but thought it would be more appropriate here.

When I try to replicate the error at the neurostars post, I get this in my python console.

Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym\tpl-MNI152NLin2009cAsym_res-02_atlas-HOSPA_desc-th25_dseg.nii.gz

Note the correct forward slashes in the url up to right before the filename, where there's a backslash instead. I can open the .nii.gz file in a text editor and read the xml error about how the file was not found.

<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>tpl-MNI152NLin2009cAsym\tpl-MNI152NLin2009cAsym_res-02_atlas-HOSPA_desc-th25_dseg.nii.gz</Key>
<RequestId>F1MJ79MTW7J2SPVK</RequestId>
<HostId>fxINO/E5QXCEhYuq8/p1EWsIwUTosPWwWNNVexR3R7P9tHWtQYue1TiOMYy4FNSuLMH4/MnyVE0=</HostId>
</Error>

The .nii.gz file is no longer zero-length and won't get overwritten, even though it's not a nifti file. I just get errors when I try to access it with nibabel.

I would say this is a bug in the templateflow code (probably because Windows is rarely used and it works fine on platforms using forward slashes?) at this line. When I manually execute the filepath function on Windows, the "subdir\filename" has that one backslash that wrecks the url when it's concatenated together on the next line. I verified on my Windows machine that

"subdir\\filename".replace("\\", "/")

correctly replaces the backslash.

mfschmidt commented 1 year ago

I have submitted a pull request that fixes this at https://github.com/templateflow/python-client/pull/107. It fixes the problem on my Windows installation, and still works on linux for me.

In addition to fixing this issue #89, I believe these other issues are the same: https://github.com/templateflow/python-client/issues/82 https://github.com/templateflow/python-client/issues/69

effigies commented 8 months ago

Should be resolved in 23.1.0.