Fmriprep: 1.4.1 templateflow proxy error

Created on 11 Jul 2019  Â·  39Comments  Â·  Source: nipreps/fmriprep

I'm getting a proxy error with a 1.4.1 singularity build. It looks like OASIS ANTs template is being downloaded when fmriprep starts and its being blocked. Is there a workaround for this where the templates don't need to download? Or would I need to have the sysadmin unblock https://templateflow.s3.amazonaws.com from firewalls? I'm not sure if its a firewall issue or just a policy of not allowing tunnels from compute nodes. I also have Sentry errors with reports being blocked, but the --notrack option eliminates these errors. The error log is pasted below.

Thanks

Downloading https://templateflow.s3.amazonaws.com/tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_T1w.nii.gz
Process Process-2:
Traceback (most recent call last):
File "/usr/local/miniconda/lib/python3.7/site-packages/urllib3/connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
File "/usr/local/miniconda/lib/python3.7/site-packages/urllib3/connectionpool.py", line 815, in _prepare_proxy
conn.connect()
File "/usr/local/miniconda/lib/python3.7/site-packages/urllib3/connection.py", line 324, in connect
self._tunnel()
File "/usr/local/miniconda/lib/python3.7/http/client.py", line 911, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 403 Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/miniconda/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/usr/local/miniconda/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/miniconda/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='templateflow.s3.amazonaws.com', port=443): Max retries exceeded with url: /tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_T1w.nii.gz (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/miniconda/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/local/miniconda/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(self._args, *self._kwargs)
File "/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/cli/run.py", line 610, in build_workflow
work_dir=str(work_dir),
File "/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/workflows/base.py", line 259, in init_fmriprep_wf
use_syn=use_syn,
File "/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/workflows/base.py", line 551, in init_single_subject_wf
skull_strip_template=skull_strip_template,
File "/usr/local/miniconda/lib/python3.7/site-packages/smriprep/workflows/anatomical.py", line 230, in init_anat_preproc_wf
normalization_quality='precise' if not debug else 'testing')
File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/anat/ants.py", line 183, in init_brain_extraction_wf
template_spec=template_spec)
File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/utils/misc.py", line 50, in get_template_specs
tpl_target_path = get_template(in_template, *template_spec)
File "/usr/local/miniconda/lib/python3.7/site-packages/templateflow/api.py", line 39, in get
_s3_get(filepath)
File "/usr/local/miniconda/lib/python3.7/site-packages/templateflow/api.py", line 130, in _s3_get
r = requests.get(url, stream=True)
File "/usr/local/miniconda/lib/python3.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, *
kwargs)
File "/usr/local/miniconda/lib/python3.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, *kwargs)
File "/usr/local/miniconda/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, *
send_kwargs)
File "/usr/local/miniconda/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/usr/local/miniconda/lib/python3.7/site-packages/requests/adapters.py", line 507, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='templateflow.s3.amazonaws.com', port=443): Max retries exceeded with url: /tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_T1w.nii.gz (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

bug templateflow

All 39 comments

Or would I need to have the sysadmin unblock https://templateflow.s3.amazonaws.com from firewalls?

Correct. Your firewall is preventing templates from being pulled down.

I am having the same problem but with OSError: [Errno 28] No space left on device

Traceback (most recent call last): File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 316, in _send_procs_to_workers self.procs[jobid].run(updatehash=updatehash) File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 472, in run result = self._run_interface(execute=True) File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 563, in _run_interface return self._run_command(execute) File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 643, in _run_command result = self._interface.run(cwd=outdir) File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py", line 375, in run runtime = self._run_interface(runtime) File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/utility/wrappers.py", line 144, in _run_interface out = function_handle(**args) File "<string>", line 5, in _get_template File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/utils/misc.py", line 50, in get_template_specs tpl_target_path = get_template(in_template, **template_spec) File "/usr/local/miniconda/lib/python3.7/site-packages/templateflow/api.py", line 39, in get _s3_get(filepath) File "/usr/local/miniconda/lib/python3.7/site-packages/templateflow/api.py", line 144, in _s3_get f.write(data) OSError: [Errno 28] No space left on device

And I assume you checked you can actually write to

python -c "from templateflow.conf import TF_HOME; print(TF_HOME)"

?

I am using singularity image

Okay, then that is potentially a different issue. What is fMRIPrep version?

the current version now, 1.4.1

And your full command line?

I was trying to run with different output spaces

singularity run -e -B /data/joy/BBL/applications/bids_apps/templateflow/:/opt/templateflow -B /data:/home/aadebimpe/data /data/joy/BBL/applications/bids_apps/fmriprep1.4.1.simg /home/aadebimpe//data/jux/BBL/projects/testACT/data/BIDS /home/aadebimpe//data/jux/BBL/projects/testACT/data/BIDS/fmriprep1.41 participant --participant_label 080557 --no-freesurfer -w /home/aadebimpe//data/jux/BBL/projects/testACT/data/BIDS/fmriprep1.41/wkdir --skip_bids_validation --force-bbr --fs-license-file license.txt --output-spaces MNI152Lin,MNI152NLin2009cAsym,MNI152NLin6Asym,MNI152NLin6Sym,NKI,OASIS30ANTs,PNC

I am getting the same error as @a3sha2. After reading the possible solutions (https://neurostars.org/t/antsbrainextraction-failure-freesurfer-does-fine/3949/32 -> export SINGULARITYENV_TEMPLATEFLOW_HOME=[..]) it is still unclear to me how to use this approach when running multiple singularity instances in parallel. Would that not give me concurrency problems when they al start downloading the same template? Do I have to prepare all the templates in advance?

This is what I see (e.g. many templates size zero):

singularity shell /opt/fmriprep/1.4.1/fmriprep-1.4.1.simg 
Singularity: Invoking an interactive shell within container...

Singularity fmriprep-1.4.1.simg:/home/mrphys/marzwi> echo $HOME
/home/fmriprep
Singularity fmriprep-1.4.1.simg:/home/mrphys/marzwi> ls -al $HOME/.cache/templateflow/tpl-OASIS30ANTs/
total 57544
drwxrwxrwx  2 root root      972 Aug  5 13:56 .
drwxrwxrwx 13 root root      295 Jul  9 13:37 ..
-rw-rw-rw-  1 root root       39 Jun  8 12:48 CHANGES
-rw-rw-rw-  1 root root      744 Jun  8 12:48 template_description.json
-rw-rw-rw-  1 root root      537 Jun  8 12:48 template_sample.tsv
-rw-rw-rw-  1 root root 32363109 Jun  8 12:48 tpl-OASIS30ANTs_res-01_T1w.nii.gz
-rw-rw-rw-  1 root root   292399 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-4_dseg.nii.gz
-rw-rw-rw-  1 root root      164 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-4_dseg.tsv
-rw-rw-rw-  1 root root   303542 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-6_dseg.nii.gz
-rw-rw-rw-  1 root root      205 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-6_dseg.tsv
-rw-rw-rw-  1 root root   264866 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-BrainCerebellumExtraction_mask.nii.gz
-rw-rw-rw-  1 root root   255798 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-BrainCerebellumRegistration_mask.nii.gz
-rw-rw-rw-  1 root root  5082326 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-brain_T1w.nii.gz
-rw-rw-rw-  1 root root   182192 Jun  8 12:48 tpl-OASIS30ANTs_res-01_desc-brain_mask.nii.gz
-rw-rw-rw-  1 root root   446641 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-BS_probseg.nii.gz
-rw-rw-rw-  1 root root   887554 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-CBM_probseg.nii.gz
-rw-rw-rw-  1 root root  5260423 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-CGM_probseg.nii.gz
-rw-rw-rw-  1 root root  6205417 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-CSF_probseg.nii.gz
-rw-rw-rw-  1 root root   726641 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-SCGM_probseg.nii.gz
-rw-rw-rw-  1 root root  4057922 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-WM_probseg.nii.gz
-rw-rw-rw-  1 root root  2589048 Jun  8 12:48 tpl-OASIS30ANTs_res-01_label-brain_probseg.nii.gz
Singularity fmriprep-1.4.1.simg:/home/mrphys/marzwi> find $HOME/.cache/templateflow -type f -size 0 | wc -l
386

I downloaded the templates I was using to a templateflow directory and this
worked fine with multiple instances.

Joseph M. Orr, PhD
Assistant Professor
Department of Psychological and Brain Sciences
Texas A&M Institute for Neuroscience
Texas A&M University
College Station, TX

On Tue, Sep 3, 2019, 3:58 AM Marcel Zwiers notifications@github.com wrote:

This is what I see:

singularity shell /opt/fmriprep/1.4.1/fmriprep-1.4.1.simg
Singularity: Invoking an interactive shell within container...

Singularity fmriprep-1.4.1.simg:/home/mrphys/marzwi> echo $HOME
/home/fmriprep
Singularity fmriprep-1.4.1.simg:/home/mrphys/marzwi> ls -al $HOME/.cache/templateflow/tpl-OASIS30ANTs/
total 57544
drwxrwxrwx 2 root root 972 Aug 5 13:56 .
drwxrwxrwx 13 root root 295 Jul 9 13:37 ..
-rw-rw-rw- 1 root root 39 Jun 8 12:48 CHANGES
-rw-rw-rw- 1 root root 744 Jun 8 12:48 template_description.json
-rw-rw-rw- 1 root root 537 Jun 8 12:48 template_sample.tsv
-rw-rw-rw- 1 root root 32363109 Jun 8 12:48 tpl-OASIS30ANTs_res-01_T1w.nii.gz
-rw-rw-rw- 1 root root 292399 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-4_dseg.nii.gz
-rw-rw-rw- 1 root root 164 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-4_dseg.tsv
-rw-rw-rw- 1 root root 303542 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-6_dseg.nii.gz
-rw-rw-rw- 1 root root 205 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-6_dseg.tsv
-rw-rw-rw- 1 root root 264866 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-BrainCerebellumExtraction_mask.nii.gz
-rw-rw-rw- 1 root root 255798 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-BrainCerebellumRegistration_mask.nii.gz
-rw-rw-rw- 1 root root 5082326 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-brain_T1w.nii.gz
-rw-rw-rw- 1 root root 182192 Jun 8 12:48 tpl-OASIS30ANTs_res-01_desc-brain_mask.nii.gz
-rw-rw-rw- 1 root root 446641 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-BS_probseg.nii.gz
-rw-rw-rw- 1 root root 887554 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-CBM_probseg.nii.gz
-rw-rw-rw- 1 root root 5260423 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-CGM_probseg.nii.gz
-rw-rw-rw- 1 root root 6205417 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-CSF_probseg.nii.gz
-rw-rw-rw- 1 root root 726641 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-SCGM_probseg.nii.gz
-rw-rw-rw- 1 root root 4057922 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-WM_probseg.nii.gz
-rw-rw-rw- 1 root root 2589048 Jun 8 12:48 tpl-OASIS30ANTs_res-01_label-brain_probseg.nii.gz

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_poldracklab_fmriprep_issues_1699-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DACBNSL6TNPE7XGGEAJAEJB3QHYRKPA5CNFSM4IBVK6F2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5XQOEA-23issuecomment-2D527370000&d=DwMCaQ&c=u6LDEWzohnDQ01ySGnxMzg&r=r5Mpc3mGXfHYvMphItda23EYv_4RBAqWoRqiqZo1OLo&m=zw4WZUSaSyWcIaGhEtchdqctNPNtAJr9Zn8gndwOMa0&s=wgISNKlXc3m3M-2STa28jGyde9HQVRiKze8Weax3r_w&e=,
or mute the thread
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_ACBNSL4FTSTTTYDA2ACW3YDQHYRKPANCNFSM4IBVK6FQ&d=DwMCaQ&c=u6LDEWzohnDQ01ySGnxMzg&r=r5Mpc3mGXfHYvMphItda23EYv_4RBAqWoRqiqZo1OLo&m=zw4WZUSaSyWcIaGhEtchdqctNPNtAJr9Zn8gndwOMa0&s=2TbrICwfUhbFiFaVuIoAZgEUvI26BikYmJXxrotn4Ok&e=
.

@marcelzwiers
this is what i did and working for 1.4.1 to current fmriprep.

export SINGULARITYENV_TEMPLATEFLOW_HOME=/home/user/templateflow
then

singularity exec -B /home/user/.cache/templateflow:/home/aadebimpe/templateflow --cleanenv fmriprep1.4.1.simg python -c “from templateflow import api; print(api.get(‘MNI152Lin’,‘MNI152NLin2009cAsym’,‘MNI152NLin6Asym’,‘MNI152NLin6Sym’,‘PNC’,resolution=2))”

then
then: note I bind the singularity at /data

singularity run -e -B /home/user/.cache/templateflow:/home/user/templateflow -B /data:/home/user/data fmriprep1.4.1.simg .........

@marcelzwiers did @a3sha2's suggestions work for you?

Maybe it could work for me, but it is a major pain for our center. I maintain a fmriprep module on our central storage that hundreds of researchers have access to. I cannot tell all of them to follow a3sha2 suggestion for every fmriprep run they want to do (people here will just stick to using the old version). Is there a plan to solve this issue for future fmriprep versions?

it will work, we also use it like that on our cluster at Penn @marcelzwiers

It should also be possible to set up a single cache for the entire cluster and include the environment variable in your module so that the templates only need to be downloaded once, and shared.

@oesteban correct me if I'm wrong, but as long as you're using a single version of fMRIPrep, there should be no chance of needing to fetch new templates, so you could have a many-to-one relationship of fMRIPrep versions to templateflow caches.

@effigies It is a bit confusing to me. So what I understood is that there is an incomplete .cache in the 1.4.1 singularity container (it is unclear to me why all the standard templates are not just simply put there), and I should manually create a single read-only(?) template cache folder on central storage that serves the different fmriprep versions on our cluster.

The alternative is that every user should do what @a3sha2 does (i.e. first run the api.get command to get the templates they need) in their own home-directory and I make the settings correct for them (i.e. do the binding) in the frmiprep common.tcl module file.

Both options seem like a major step down for us, compared to the previous fmriprep versions

TBH it's not really clear to me why these aren't showing up on Singularity images. They should be present in the Docker images, and Singularity should replicate that. But I believe Oscar has looked into this more. Possibly we're downloading the templates into a directory that doesn't get searched, when Singularity pulls in most of the host environment?

Ah, yes:

https://github.com/poldracklab/fmriprep/blob/e8e740411d7c83c4af4526f82e862ae9363ab055/Dockerfile#L164-L170

We're pulling them into $HOME for some reason, so they naturally won't exist for your user. What if you just set:

export SINGULARITYENV_TEMPLATEFLOW_HOME=/home/fmriprep/.cache/templateflow

And in future versions, we can set TEMPLATEFLOW_HOME=/home/fmriprep/.cache/templateflow inside the container.

Thanks @effigies I will try that first

NB, there are many standard templates of size zero in the singularity container, is that different in the docker? See e.g.:

Singularity fmriprep-1.4.1.simg:/home/mrphys/marzwi> ls -al /home/fmriprep/.cache/templateflow/tpl-MNI152Lin/
total 3
drwxrwxrwx  3 root root  539 Aug  5 13:56 .
drwxrwxrwx 13 root root  295 Jul  9 13:37 ..
-rw-rw-rw-  1 root root  196 Jun  8 12:48 CHANGES
-rw-rw-rw-  1 root root  678 Jun  8 12:48 LICENSE
drwxrwxrwx  2 root root   73 Aug  5 13:56 scripts
-rw-rw-rw-  1 root root 1248 Jun  8 12:48 template_description.json
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-01_PD.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-01_T1w.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-01_T2w.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-01_desc-brain_mask.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-01_desc-head_mask.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-02_PD.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-02_T1w.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-02_T2w.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-02_desc-brain_mask.nii.gz
-rw-rw-rw-  1 root root    0 Jun  8 12:48 tpl-MNI152Lin_res-02_desc-head_mask.nii.gz

That's the same in the Docker. The Docker image only provides the three we use by default, but the templateflow package is intended to aggregate a lot of of templates, not just as a component of fMRIPrep.

So you will run into issues if people want to use templates besides these, at which point being able to provide alternative locations for the cache will be useful.

Maybe it would be good to add that to the docs, that these are the fmriprep standard templates... It now says:

--output-spaces

Standard and non-standard spaces to resample anatomical and functional images to. Standard spaces may be specified by the form