0s autopkgtest [11:37:13]: starting date and time: 2024-06-16 11:37:13+0000 0s autopkgtest [11:37:13]: git checkout: 433ed4cb Merge branch 'skia/nova_flock' into 'ubuntu/5.34+prod' 0s autopkgtest [11:37:13]: host juju-7f2275-prod-proposed-migration-environment-2; command line: /home/ubuntu/autopkgtest/runner/autopkgtest --output-dir /tmp/autopkgtest-work.w603r6ny/out --timeout-copy=6000 --setup-commands /home/ubuntu/autopkgtest-cloud/worker-config-production/setup-canonical.sh --apt-pocket=proposed=src:traitlets --apt-upgrade jupyter-notebook --timeout-short=300 --timeout-copy=20000 --timeout-build=20000 --env=ADT_TEST_TRIGGERS=traitlets/5.14.3-1 -- ssh -s /home/ubuntu/autopkgtest/ssh-setup/nova -- --flavor autopkgtest --security-groups autopkgtest-juju-7f2275-prod-proposed-migration-environment-2@bos03-arm64-46.secgroup --name adt-oracular-arm64-jupyter-notebook-20240616-102219-juju-7f2275-prod-proposed-migration-environment-2-3fa41470-9ba7-4314-bf5b-5890bf50c62a --image adt/ubuntu-oracular-arm64-server --keyname testbed-juju-7f2275-prod-proposed-migration-environment-2 --net-id=net_prod-proposed-migration -e TERM=linux -e ''"'"'http_proxy=http://squid.internal:3128'"'"'' -e ''"'"'https_proxy=http://squid.internal:3128'"'"'' -e ''"'"'no_proxy=127.0.0.1,127.0.1.1,login.ubuntu.com,localhost,localdomain,novalocal,internal,archive.ubuntu.com,ports.ubuntu.com,security.ubuntu.com,ddebs.ubuntu.com,changelogs.ubuntu.com,keyserver.ubuntu.com,launchpadlibrarian.net,launchpadcontent.net,launchpad.net,10.24.0.0/24,keystone.ps5.canonical.com,objectstorage.prodstack5.canonical.com'"'"'' --mirror=http://ftpmaster.internal/ubuntu/ 58s autopkgtest [11:38:11]: testbed dpkg architecture: arm64 58s autopkgtest [11:38:11]: testbed apt version: 2.9.5 58s autopkgtest [11:38:11]: @@@@@@@@@@@@@@@@@@@@ test bed setup 58s Get:1 http://ftpmaster.internal/ubuntu oracular-proposed InRelease [110 kB] 59s Get:2 http://ftpmaster.internal/ubuntu oracular-proposed/main Sources [36.1 kB] 59s Get:3 http://ftpmaster.internal/ubuntu oracular-proposed/restricted Sources [7052 B] 59s Get:4 http://ftpmaster.internal/ubuntu oracular-proposed/multiverse Sources [2576 B] 59s Get:5 http://ftpmaster.internal/ubuntu oracular-proposed/universe Sources [388 kB] 59s Get:6 http://ftpmaster.internal/ubuntu oracular-proposed/main arm64 Packages [55.3 kB] 59s Get:7 http://ftpmaster.internal/ubuntu oracular-proposed/restricted arm64 Packages [33.3 kB] 59s Get:8 http://ftpmaster.internal/ubuntu oracular-proposed/universe arm64 Packages [311 kB] 59s Get:9 http://ftpmaster.internal/ubuntu oracular-proposed/multiverse arm64 Packages [8312 B] 59s Fetched 952 kB in 1s (963 kB/s) 59s Reading package lists... 62s Reading package lists... 62s Building dependency tree... 62s Reading state information... 62s Calculating upgrade... 63s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 63s Reading package lists... 64s Building dependency tree... 64s Reading state information... 65s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 65s Hit:1 http://ftpmaster.internal/ubuntu oracular InRelease 65s Hit:2 http://ftpmaster.internal/ubuntu oracular-updates InRelease 66s Hit:3 http://ftpmaster.internal/ubuntu oracular-security InRelease 66s Hit:4 http://ftpmaster.internal/ubuntu oracular-proposed InRelease 67s Reading package lists... 67s Reading package lists... 67s Building dependency tree... 67s Reading state information... 67s Calculating upgrade... 68s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 68s Reading package lists... 68s Building dependency tree... 68s Reading state information... 69s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 72s autopkgtest [11:38:25]: testbed running kernel: Linux 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 02:32:42 UTC 2024 72s autopkgtest [11:38:25]: @@@@@@@@@@@@@@@@@@@@ apt-source jupyter-notebook 76s Get:1 http://ftpmaster.internal/ubuntu oracular/universe jupyter-notebook 6.4.12-2.2ubuntu1 (dsc) [3886 B] 76s Get:2 http://ftpmaster.internal/ubuntu oracular/universe jupyter-notebook 6.4.12-2.2ubuntu1 (tar) [8501 kB] 76s Get:3 http://ftpmaster.internal/ubuntu oracular/universe jupyter-notebook 6.4.12-2.2ubuntu1 (diff) [49.6 kB] 77s gpgv: Signature made Thu Feb 15 18:11:52 2024 UTC 77s gpgv: using RSA key D09F8A854F1055BCFC482C4B23566B906047AFC8 77s gpgv: Can't check signature: No public key 77s dpkg-source: warning: cannot verify inline signature for ./jupyter-notebook_6.4.12-2.2ubuntu1.dsc: no acceptable signature found 78s autopkgtest [11:38:31]: testing package jupyter-notebook version 6.4.12-2.2ubuntu1 78s autopkgtest [11:38:31]: build not needed 79s autopkgtest [11:38:32]: test pytest: preparing testbed 80s Reading package lists... 81s Building dependency tree... 81s Reading state information... 81s Starting pkgProblemResolver with broken count: 0 81s Starting 2 pkgProblemResolver with broken count: 0 81s Done 82s The following additional packages will be installed: 82s fonts-font-awesome fonts-glyphicons-halflings fonts-lato fonts-mathjax gdb 82s jupyter-core jupyter-notebook libbabeltrace1 libdebuginfod-common 82s libdebuginfod1t64 libjs-backbone libjs-bootstrap libjs-bootstrap-tour 82s libjs-codemirror libjs-es6-promise libjs-jed libjs-jquery 82s libjs-jquery-typeahead libjs-jquery-ui libjs-marked libjs-mathjax 82s libjs-moment libjs-requirejs libjs-requirejs-text libjs-sphinxdoc 82s libjs-text-encoding libjs-underscore libjs-xterm libnorm1t64 libpgm-5.3-0t64 82s libpython3.12t64 libsodium23 libsource-highlight-common 82s libsource-highlight4t64 libzmq5 node-jed python-notebook-doc 82s python-tinycss2-common python3-argon2 python3-asttokens python3-bleach 82s python3-bs4 python3-bytecode python3-comm python3-coverage python3-dateutil 82s python3-debugpy python3-decorator python3-defusedxml python3-entrypoints 82s python3-executing python3-fastjsonschema python3-html5lib python3-iniconfig 82s python3-ipykernel python3-ipython python3-ipython-genutils python3-jedi 82s python3-jupyter-client python3-jupyter-core python3-jupyterlab-pygments 82s python3-matplotlib-inline python3-mistune python3-nbclient python3-nbconvert 82s python3-nbformat python3-nest-asyncio python3-notebook python3-packaging 82s python3-pandocfilters python3-parso python3-pexpect python3-platformdirs 82s python3-pluggy python3-prometheus-client python3-prompt-toolkit 82s python3-psutil python3-ptyprocess python3-pure-eval python3-py 82s python3-pydevd python3-pytest python3-requests-unixsocket python3-send2trash 82s python3-setuptools python3-soupsieve python3-stack-data python3-terminado 82s python3-tinycss2 python3-tornado python3-traitlets python3-typeshed 82s python3-wcwidth python3-webencodings python3-zmq sphinx-rtd-theme-common 82s Suggested packages: 82s gdb-doc gdbserver libjs-jquery-lazyload libjs-json libjs-jquery-ui-docs 82s fonts-mathjax-extras fonts-stix libjs-mathjax-doc python-argon2-doc 82s python-bleach-doc python-bytecode-doc python-coverage-doc 82s python-fastjsonschema-doc python3-genshi python3-lxml python-ipython-doc 82s python3-pip python-nbconvert-doc texlive-fonts-recommended 82s texlive-plain-generic texlive-xetex python-pexpect-doc subversion pydevd 82s python-setuptools-doc python-terminado-doc python-tinycss2-doc 82s python3-pycurl python-tornado-doc python3-twisted 82s Recommended packages: 82s libc-dbg javascript-common python3-lxml python3-matplotlib pandoc 82s python3-ipywidgets 82s The following NEW packages will be installed: 82s autopkgtest-satdep fonts-font-awesome fonts-glyphicons-halflings fonts-lato 82s fonts-mathjax gdb jupyter-core jupyter-notebook libbabeltrace1 82s libdebuginfod-common libdebuginfod1t64 libjs-backbone libjs-bootstrap 82s libjs-bootstrap-tour libjs-codemirror libjs-es6-promise libjs-jed 82s libjs-jquery libjs-jquery-typeahead libjs-jquery-ui libjs-marked 82s libjs-mathjax libjs-moment libjs-requirejs libjs-requirejs-text 82s libjs-sphinxdoc libjs-text-encoding libjs-underscore libjs-xterm libnorm1t64 82s libpgm-5.3-0t64 libpython3.12t64 libsodium23 libsource-highlight-common 82s libsource-highlight4t64 libzmq5 node-jed python-notebook-doc 82s python-tinycss2-common python3-argon2 python3-asttokens python3-bleach 82s python3-bs4 python3-bytecode python3-comm python3-coverage python3-dateutil 82s python3-debugpy python3-decorator python3-defusedxml python3-entrypoints 82s python3-executing python3-fastjsonschema python3-html5lib python3-iniconfig 82s python3-ipykernel python3-ipython python3-ipython-genutils python3-jedi 82s python3-jupyter-client python3-jupyter-core python3-jupyterlab-pygments 82s python3-matplotlib-inline python3-mistune python3-nbclient python3-nbconvert 82s python3-nbformat python3-nest-asyncio python3-notebook python3-packaging 82s python3-pandocfilters python3-parso python3-pexpect python3-platformdirs 82s python3-pluggy python3-prometheus-client python3-prompt-toolkit 82s python3-psutil python3-ptyprocess python3-pure-eval python3-py 82s python3-pydevd python3-pytest python3-requests-unixsocket python3-send2trash 82s python3-setuptools python3-soupsieve python3-stack-data python3-terminado 82s python3-tinycss2 python3-tornado python3-traitlets python3-typeshed 82s python3-wcwidth python3-webencodings python3-zmq sphinx-rtd-theme-common 82s 0 upgraded, 97 newly installed, 0 to remove and 0 not upgraded. 82s Need to get 34.5 MB/34.5 MB of archives. 82s After this operation, 178 MB of additional disk space will be used. 82s Get:1 /tmp/autopkgtest.MsnsbA/1-autopkgtest-satdep.deb autopkgtest-satdep arm64 0 [748 B] 82s Get:2 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-lato all 2.015-1 [2781 kB] 83s Get:3 http://ftpmaster.internal/ubuntu oracular/main arm64 libdebuginfod-common all 0.191-1 [14.6 kB] 83s Get:4 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-font-awesome all 5.0.10+really4.7.0~dfsg-4.1 [516 kB] 83s Get:5 http://ftpmaster.internal/ubuntu oracular/universe arm64 fonts-glyphicons-halflings all 1.009~3.4.1+dfsg-3 [118 kB] 83s Get:6 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-mathjax all 2.7.9+dfsg-1 [2208 kB] 83s Get:7 http://ftpmaster.internal/ubuntu oracular/main arm64 libbabeltrace1 arm64 1.5.11-3build3 [159 kB] 83s Get:8 http://ftpmaster.internal/ubuntu oracular/main arm64 libdebuginfod1t64 arm64 0.191-1 [16.2 kB] 83s Get:9 http://ftpmaster.internal/ubuntu oracular/main arm64 libpython3.12t64 arm64 3.12.4-1 [2280 kB] 83s Get:10 http://ftpmaster.internal/ubuntu oracular/main arm64 libsource-highlight-common all 3.1.9-4.3build1 [64.2 kB] 83s Get:11 http://ftpmaster.internal/ubuntu oracular/main arm64 libsource-highlight4t64 arm64 3.1.9-4.3build1 [243 kB] 83s Get:12 http://ftpmaster.internal/ubuntu oracular/main arm64 gdb arm64 15.0.50.20240403-0ubuntu1 [4837 kB] 83s Get:13 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-platformdirs all 4.2.1-1 [16.3 kB] 83s Get:14 http://ftpmaster.internal/ubuntu oracular-proposed/universe arm64 python3-traitlets all 5.14.3-1 [71.3 kB] 83s Get:15 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyter-core all 5.3.2-2 [25.5 kB] 83s Get:16 http://ftpmaster.internal/ubuntu oracular/universe arm64 jupyter-core all 5.3.2-2 [4038 B] 83s Get:17 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-underscore all 1.13.4~dfsg+~1.11.4-3 [118 kB] 83s Get:18 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-backbone all 1.4.1~dfsg+~1.4.15-3 [185 kB] 83s Get:19 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-bootstrap all 3.4.1+dfsg-3 [129 kB] 83s Get:20 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-jquery all 3.6.1+dfsg+~3.5.14-1 [328 kB] 83s Get:21 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-bootstrap-tour all 0.12.0+dfsg-5 [21.4 kB] 83s Get:22 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-codemirror all 5.65.0+~cs5.83.9-3 [755 kB] 83s Get:23 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-es6-promise all 4.2.8-12 [14.1 kB] 83s Get:24 http://ftpmaster.internal/ubuntu oracular/universe arm64 node-jed all 1.1.1-4 [15.2 kB] 83s Get:25 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jed all 1.1.1-4 [2584 B] 83s Get:26 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jquery-typeahead all 2.11.0+dfsg1-3 [48.9 kB] 83s Get:27 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jquery-ui all 1.13.2+dfsg-1 [252 kB] 83s Get:28 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-marked all 4.2.3+ds+~4.0.7-3 [36.2 kB] 83s Get:29 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-mathjax all 2.7.9+dfsg-1 [5665 kB] 83s Get:30 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-moment all 2.29.4+ds-1 [147 kB] 83s Get:31 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-requirejs all 2.3.6+ds+~2.1.37-1 [201 kB] 83s Get:32 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-requirejs-text all 2.0.12-1.1 [9056 B] 83s Get:33 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-text-encoding all 0.7.0-5 [140 kB] 83s Get:34 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-xterm all 5.3.0-2 [476 kB] 83s Get:35 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-ptyprocess all 0.7.0-5 [15.1 kB] 83s Get:36 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-tornado arm64 6.4.1-1 [298 kB] 83s Get:37 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-terminado all 0.18.1-1 [13.2 kB] 83s Get:38 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-argon2 arm64 21.1.0-2build1 [21.4 kB] 83s Get:39 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-comm all 0.2.1-1 [7016 B] 83s Get:40 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-bytecode all 0.15.1-3 [44.7 kB] 83s Get:41 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-coverage arm64 7.4.4+dfsg1-0ubuntu2 [148 kB] 83s Get:42 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pydevd arm64 2.10.0+ds-10ubuntu1 [600 kB] 83s Get:43 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-debugpy all 1.8.0+ds-4ubuntu4 [67.6 kB] 83s Get:44 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-decorator all 5.1.1-5 [10.1 kB] 83s Get:45 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-parso all 0.8.3-1 [67.2 kB] 83s Get:46 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-typeshed all 0.0~git20231111.6764465-3 [1274 kB] 83s Get:47 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jedi all 0.19.1+ds1-1 [693 kB] 83s Get:48 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-matplotlib-inline all 0.1.6-2 [8784 B] 83s Get:49 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-pexpect all 4.9-2 [48.1 kB] 83s Get:50 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-wcwidth all 0.2.5+dfsg1-1.1ubuntu1 [22.5 kB] 83s Get:51 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-prompt-toolkit all 3.0.46-1 [256 kB] 83s Get:52 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-asttokens all 2.4.1-1 [20.9 kB] 83s Get:53 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-executing all 2.0.1-0.1 [23.3 kB] 83s Get:54 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pure-eval all 0.2.2-2 [11.1 kB] 83s Get:55 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-stack-data all 0.6.3-1 [22.0 kB] 83s Get:56 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-setuptools all 68.1.2-2ubuntu1 [396 kB] 83s Get:57 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipython all 8.20.0-1ubuntu1 [561 kB] 83s Get:58 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-dateutil all 2.9.0-2 [80.3 kB] 83s Get:59 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-entrypoints all 0.4-2 [7146 B] 83s Get:60 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nest-asyncio all 1.5.4-1 [6256 B] 83s Get:61 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-py all 1.11.0-2 [72.7 kB] 84s Get:62 http://ftpmaster.internal/ubuntu oracular/universe arm64 libnorm1t64 arm64 1.5.9+dfsg-3.1build1 [150 kB] 84s Get:63 http://ftpmaster.internal/ubuntu oracular/universe arm64 libpgm-5.3-0t64 arm64 5.3.128~dfsg-2.1build1 [162 kB] 84s Get:64 http://ftpmaster.internal/ubuntu oracular/main arm64 libsodium23 arm64 1.0.18-1build3 [119 kB] 84s Get:65 http://ftpmaster.internal/ubuntu oracular/universe arm64 libzmq5 arm64 4.3.5-1build2 [247 kB] 84s Get:66 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-zmq arm64 24.0.1-5build1 [280 kB] 84s Get:67 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyter-client all 7.4.9-2ubuntu1 [90.5 kB] 84s Get:68 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-packaging all 24.0-1 [41.1 kB] 84s Get:69 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-psutil arm64 5.9.8-2build2 [196 kB] 84s Get:70 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipykernel all 6.29.3-1ubuntu1 [82.6 kB] 84s Get:71 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipython-genutils all 0.2.0-6 [22.0 kB] 84s Get:72 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-webencodings all 0.5.1-5 [11.5 kB] 84s Get:73 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-html5lib all 1.1-6 [88.8 kB] 84s Get:74 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-bleach all 6.1.0-2 [49.6 kB] 84s Get:75 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-soupsieve all 2.5-1 [33.0 kB] 84s Get:76 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-bs4 all 4.12.3-1 [109 kB] 84s Get:77 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-defusedxml all 0.7.1-2 [42.0 kB] 84s Get:78 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyterlab-pygments all 0.2.2-3 [6054 B] 84s Get:79 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-mistune all 3.0.2-1 [32.8 kB] 84s Get:80 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-fastjsonschema all 2.19.1-1 [19.7 kB] 84s Get:81 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbformat all 5.9.1-1 [41.2 kB] 84s Get:82 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbclient all 0.8.0-1 [55.6 kB] 84s Get:83 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pandocfilters all 1.5.1-1 [23.6 kB] 84s Get:84 http://ftpmaster.internal/ubuntu oracular/universe arm64 python-tinycss2-common all 1.3.0-1 [34.1 kB] 84s Get:85 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-tinycss2 all 1.3.0-1 [19.6 kB] 84s Get:86 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbconvert all 7.16.4-1 [156 kB] 84s Get:87 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-prometheus-client all 0.19.0+ds1-1 [41.7 kB] 84s Get:88 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-send2trash all 1.8.2-1 [15.5 kB] 84s Get:89 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-notebook all 6.4.12-2.2ubuntu1 [1566 kB] 84s Get:90 http://ftpmaster.internal/ubuntu oracular/universe arm64 jupyter-notebook all 6.4.12-2.2ubuntu1 [10.4 kB] 84s Get:91 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-sphinxdoc all 7.2.6-8 [150 kB] 84s Get:92 http://ftpmaster.internal/ubuntu oracular/main arm64 sphinx-rtd-theme-common all 2.0.0+dfsg-1 [1012 kB] 84s Get:93 http://ftpmaster.internal/ubuntu oracular/universe arm64 python-notebook-doc all 6.4.12-2.2ubuntu1 [2540 kB] 84s Get:94 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-iniconfig all 1.1.1-2 [6024 B] 84s Get:95 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pluggy all 1.5.0-1 [21.0 kB] 84s Get:96 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pytest all 7.4.4-1 [305 kB] 84s Get:97 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-requests-unixsocket all 0.3.0-4 [7274 B] 85s Preconfiguring packages ... 85s Fetched 34.5 MB in 2s (15.8 MB/s) 85s Selecting previously unselected package fonts-lato. 86s (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 78264 files and directories currently installed.) 86s Preparing to unpack .../00-fonts-lato_2.015-1_all.deb ... 86s Unpacking fonts-lato (2.015-1) ... 86s Selecting previously unselected package libdebuginfod-common. 86s Preparing to unpack .../01-libdebuginfod-common_0.191-1_all.deb ... 86s Unpacking libdebuginfod-common (0.191-1) ... 86s Selecting previously unselected package fonts-font-awesome. 86s Preparing to unpack .../02-fonts-font-awesome_5.0.10+really4.7.0~dfsg-4.1_all.deb ... 86s Unpacking fonts-font-awesome (5.0.10+really4.7.0~dfsg-4.1) ... 86s Selecting previously unselected package fonts-glyphicons-halflings. 86s Preparing to unpack .../03-fonts-glyphicons-halflings_1.009~3.4.1+dfsg-3_all.deb ... 86s Unpacking fonts-glyphicons-halflings (1.009~3.4.1+dfsg-3) ... 86s Selecting previously unselected package fonts-mathjax. 86s Preparing to unpack .../04-fonts-mathjax_2.7.9+dfsg-1_all.deb ... 86s Unpacking fonts-mathjax (2.7.9+dfsg-1) ... 87s Selecting previously unselected package libbabeltrace1:arm64. 87s Preparing to unpack .../05-libbabeltrace1_1.5.11-3build3_arm64.deb ... 87s Unpacking libbabeltrace1:arm64 (1.5.11-3build3) ... 87s Selecting previously unselected package libdebuginfod1t64:arm64. 87s Preparing to unpack .../06-libdebuginfod1t64_0.191-1_arm64.deb ... 87s Unpacking libdebuginfod1t64:arm64 (0.191-1) ... 87s Selecting previously unselected package libpython3.12t64:arm64. 87s Preparing to unpack .../07-libpython3.12t64_3.12.4-1_arm64.deb ... 87s Unpacking libpython3.12t64:arm64 (3.12.4-1) ... 87s Selecting previously unselected package libsource-highlight-common. 87s Preparing to unpack .../08-libsource-highlight-common_3.1.9-4.3build1_all.deb ... 87s Unpacking libsource-highlight-common (3.1.9-4.3build1) ... 87s Selecting previously unselected package libsource-highlight4t64:arm64. 87s Preparing to unpack .../09-libsource-highlight4t64_3.1.9-4.3build1_arm64.deb ... 87s Unpacking libsource-highlight4t64:arm64 (3.1.9-4.3build1) ... 87s Selecting previously unselected package gdb. 87s Preparing to unpack .../10-gdb_15.0.50.20240403-0ubuntu1_arm64.deb ... 87s Unpacking gdb (15.0.50.20240403-0ubuntu1) ... 87s Selecting previously unselected package python3-platformdirs. 87s Preparing to unpack .../11-python3-platformdirs_4.2.1-1_all.deb ... 87s Unpacking python3-platformdirs (4.2.1-1) ... 87s Selecting previously unselected package python3-traitlets. 87s Preparing to unpack .../12-python3-traitlets_5.14.3-1_all.deb ... 87s Unpacking python3-traitlets (5.14.3-1) ... 87s Selecting previously unselected package python3-jupyter-core. 87s Preparing to unpack .../13-python3-jupyter-core_5.3.2-2_all.deb ... 87s Unpacking python3-jupyter-core (5.3.2-2) ... 87s Selecting previously unselected package jupyter-core. 87s Preparing to unpack .../14-jupyter-core_5.3.2-2_all.deb ... 87s Unpacking jupyter-core (5.3.2-2) ... 87s Selecting previously unselected package libjs-underscore. 87s Preparing to unpack .../15-libjs-underscore_1.13.4~dfsg+~1.11.4-3_all.deb ... 87s Unpacking libjs-underscore (1.13.4~dfsg+~1.11.4-3) ... 87s Selecting previously unselected package libjs-backbone. 87s Preparing to unpack .../16-libjs-backbone_1.4.1~dfsg+~1.4.15-3_all.deb ... 87s Unpacking libjs-backbone (1.4.1~dfsg+~1.4.15-3) ... 87s Selecting previously unselected package libjs-bootstrap. 87s Preparing to unpack .../17-libjs-bootstrap_3.4.1+dfsg-3_all.deb ... 87s Unpacking libjs-bootstrap (3.4.1+dfsg-3) ... 87s Selecting previously unselected package libjs-jquery. 87s Preparing to unpack .../18-libjs-jquery_3.6.1+dfsg+~3.5.14-1_all.deb ... 87s Unpacking libjs-jquery (3.6.1+dfsg+~3.5.14-1) ... 88s Selecting previously unselected package libjs-bootstrap-tour. 88s Preparing to unpack .../19-libjs-bootstrap-tour_0.12.0+dfsg-5_all.deb ... 88s Unpacking libjs-bootstrap-tour (0.12.0+dfsg-5) ... 88s Selecting previously unselected package libjs-codemirror. 88s Preparing to unpack .../20-libjs-codemirror_5.65.0+~cs5.83.9-3_all.deb ... 88s Unpacking libjs-codemirror (5.65.0+~cs5.83.9-3) ... 88s Selecting previously unselected package libjs-es6-promise. 88s Preparing to unpack .../21-libjs-es6-promise_4.2.8-12_all.deb ... 88s Unpacking libjs-es6-promise (4.2.8-12) ... 88s Selecting previously unselected package node-jed. 88s Preparing to unpack .../22-node-jed_1.1.1-4_all.deb ... 88s Unpacking node-jed (1.1.1-4) ... 88s Selecting previously unselected package libjs-jed. 88s Preparing to unpack .../23-libjs-jed_1.1.1-4_all.deb ... 88s Unpacking libjs-jed (1.1.1-4) ... 88s Selecting previously unselected package libjs-jquery-typeahead. 88s Preparing to unpack .../24-libjs-jquery-typeahead_2.11.0+dfsg1-3_all.deb ... 88s Unpacking libjs-jquery-typeahead (2.11.0+dfsg1-3) ... 88s Selecting previously unselected package libjs-jquery-ui. 88s Preparing to unpack .../25-libjs-jquery-ui_1.13.2+dfsg-1_all.deb ... 88s Unpacking libjs-jquery-ui (1.13.2+dfsg-1) ... 88s Selecting previously unselected package libjs-marked. 88s Preparing to unpack .../26-libjs-marked_4.2.3+ds+~4.0.7-3_all.deb ... 88s Unpacking libjs-marked (4.2.3+ds+~4.0.7-3) ... 88s Selecting previously unselected package libjs-mathjax. 88s Preparing to unpack .../27-libjs-mathjax_2.7.9+dfsg-1_all.deb ... 88s Unpacking libjs-mathjax (2.7.9+dfsg-1) ... 89s Selecting previously unselected package libjs-moment. 89s Preparing to unpack .../28-libjs-moment_2.29.4+ds-1_all.deb ... 89s Unpacking libjs-moment (2.29.4+ds-1) ... 89s Selecting previously unselected package libjs-requirejs. 89s Preparing to unpack .../29-libjs-requirejs_2.3.6+ds+~2.1.37-1_all.deb ... 89s Unpacking libjs-requirejs (2.3.6+ds+~2.1.37-1) ... 89s Selecting previously unselected package libjs-requirejs-text. 89s Preparing to unpack .../30-libjs-requirejs-text_2.0.12-1.1_all.deb ... 89s Unpacking libjs-requirejs-text (2.0.12-1.1) ... 89s Selecting previously unselected package libjs-text-encoding. 89s Preparing to unpack .../31-libjs-text-encoding_0.7.0-5_all.deb ... 89s Unpacking libjs-text-encoding (0.7.0-5) ... 89s Selecting previously unselected package libjs-xterm. 89s Preparing to unpack .../32-libjs-xterm_5.3.0-2_all.deb ... 89s Unpacking libjs-xterm (5.3.0-2) ... 89s Selecting previously unselected package python3-ptyprocess. 89s Preparing to unpack .../33-python3-ptyprocess_0.7.0-5_all.deb ... 89s Unpacking python3-ptyprocess (0.7.0-5) ... 89s Selecting previously unselected package python3-tornado. 89s Preparing to unpack .../34-python3-tornado_6.4.1-1_arm64.deb ... 89s Unpacking python3-tornado (6.4.1-1) ... 89s Selecting previously unselected package python3-terminado. 89s Preparing to unpack .../35-python3-terminado_0.18.1-1_all.deb ... 89s Unpacking python3-terminado (0.18.1-1) ... 89s Selecting previously unselected package python3-argon2. 89s Preparing to unpack .../36-python3-argon2_21.1.0-2build1_arm64.deb ... 89s Unpacking python3-argon2 (21.1.0-2build1) ... 89s Selecting previously unselected package python3-comm. 89s Preparing to unpack .../37-python3-comm_0.2.1-1_all.deb ... 89s Unpacking python3-comm (0.2.1-1) ... 89s Selecting previously unselected package python3-bytecode. 89s Preparing to unpack .../38-python3-bytecode_0.15.1-3_all.deb ... 89s Unpacking python3-bytecode (0.15.1-3) ... 89s Selecting previously unselected package python3-coverage. 89s Preparing to unpack .../39-python3-coverage_7.4.4+dfsg1-0ubuntu2_arm64.deb ... 89s Unpacking python3-coverage (7.4.4+dfsg1-0ubuntu2) ... 90s Selecting previously unselected package python3-pydevd. 90s Preparing to unpack .../40-python3-pydevd_2.10.0+ds-10ubuntu1_arm64.deb ... 90s Unpacking python3-pydevd (2.10.0+ds-10ubuntu1) ... 90s Selecting previously unselected package python3-debugpy. 90s Preparing to unpack .../41-python3-debugpy_1.8.0+ds-4ubuntu4_all.deb ... 90s Unpacking python3-debugpy (1.8.0+ds-4ubuntu4) ... 90s Selecting previously unselected package python3-decorator. 90s Preparing to unpack .../42-python3-decorator_5.1.1-5_all.deb ... 90s Unpacking python3-decorator (5.1.1-5) ... 90s Selecting previously unselected package python3-parso. 90s Preparing to unpack .../43-python3-parso_0.8.3-1_all.deb ... 90s Unpacking python3-parso (0.8.3-1) ... 90s Selecting previously unselected package python3-typeshed. 90s Preparing to unpack .../44-python3-typeshed_0.0~git20231111.6764465-3_all.deb ... 90s Unpacking python3-typeshed (0.0~git20231111.6764465-3) ... 90s Selecting previously unselected package python3-jedi. 90s Preparing to unpack .../45-python3-jedi_0.19.1+ds1-1_all.deb ... 90s Unpacking python3-jedi (0.19.1+ds1-1) ... 90s Selecting previously unselected package python3-matplotlib-inline. 90s Preparing to unpack .../46-python3-matplotlib-inline_0.1.6-2_all.deb ... 90s Unpacking python3-matplotlib-inline (0.1.6-2) ... 90s Selecting previously unselected package python3-pexpect. 90s Preparing to unpack .../47-python3-pexpect_4.9-2_all.deb ... 90s Unpacking python3-pexpect (4.9-2) ... 91s Selecting previously unselected package python3-wcwidth. 91s Preparing to unpack .../48-python3-wcwidth_0.2.5+dfsg1-1.1ubuntu1_all.deb ... 91s Unpacking python3-wcwidth (0.2.5+dfsg1-1.1ubuntu1) ... 91s Selecting previously unselected package python3-prompt-toolkit. 91s Preparing to unpack .../49-python3-prompt-toolkit_3.0.46-1_all.deb ... 91s Unpacking python3-prompt-toolkit (3.0.46-1) ... 91s Selecting previously unselected package python3-asttokens. 91s Preparing to unpack .../50-python3-asttokens_2.4.1-1_all.deb ... 91s Unpacking python3-asttokens (2.4.1-1) ... 91s Selecting previously unselected package python3-executing. 91s Preparing to unpack .../51-python3-executing_2.0.1-0.1_all.deb ... 91s Unpacking python3-executing (2.0.1-0.1) ... 91s Selecting previously unselected package python3-pure-eval. 91s Preparing to unpack .../52-python3-pure-eval_0.2.2-2_all.deb ... 91s Unpacking python3-pure-eval (0.2.2-2) ... 91s Selecting previously unselected package python3-stack-data. 91s Preparing to unpack .../53-python3-stack-data_0.6.3-1_all.deb ... 91s Unpacking python3-stack-data (0.6.3-1) ... 91s Selecting previously unselected package python3-setuptools. 91s Preparing to unpack .../54-python3-setuptools_68.1.2-2ubuntu1_all.deb ... 91s Unpacking python3-setuptools (68.1.2-2ubuntu1) ... 91s Selecting previously unselected package python3-ipython. 91s Preparing to unpack .../55-python3-ipython_8.20.0-1ubuntu1_all.deb ... 91s Unpacking python3-ipython (8.20.0-1ubuntu1) ... 91s Selecting previously unselected package python3-dateutil. 91s Preparing to unpack .../56-python3-dateutil_2.9.0-2_all.deb ... 91s Unpacking python3-dateutil (2.9.0-2) ... 91s Selecting previously unselected package python3-entrypoints. 91s Preparing to unpack .../57-python3-entrypoints_0.4-2_all.deb ... 91s Unpacking python3-entrypoints (0.4-2) ... 91s Selecting previously unselected package python3-nest-asyncio. 92s Preparing to unpack .../58-python3-nest-asyncio_1.5.4-1_all.deb ... 92s Unpacking python3-nest-asyncio (1.5.4-1) ... 92s Selecting previously unselected package python3-py. 92s Preparing to unpack .../59-python3-py_1.11.0-2_all.deb ... 92s Unpacking python3-py (1.11.0-2) ... 92s Selecting previously unselected package libnorm1t64:arm64. 92s Preparing to unpack .../60-libnorm1t64_1.5.9+dfsg-3.1build1_arm64.deb ... 92s Unpacking libnorm1t64:arm64 (1.5.9+dfsg-3.1build1) ... 92s Selecting previously unselected package libpgm-5.3-0t64:arm64. 92s Preparing to unpack .../61-libpgm-5.3-0t64_5.3.128~dfsg-2.1build1_arm64.deb ... 92s Unpacking libpgm-5.3-0t64:arm64 (5.3.128~dfsg-2.1build1) ... 92s Selecting previously unselected package libsodium23:arm64. 92s Preparing to unpack .../62-libsodium23_1.0.18-1build3_arm64.deb ... 92s Unpacking libsodium23:arm64 (1.0.18-1build3) ... 92s Selecting previously unselected package libzmq5:arm64. 93s Preparing to unpack .../63-libzmq5_4.3.5-1build2_arm64.deb ... 93s Unpacking libzmq5:arm64 (4.3.5-1build2) ... 93s Selecting previously unselected package python3-zmq. 93s Preparing to unpack .../64-python3-zmq_24.0.1-5build1_arm64.deb ... 93s Unpacking python3-zmq (24.0.1-5build1) ... 93s Selecting previously unselected package python3-jupyter-client. 93s Preparing to unpack .../65-python3-jupyter-client_7.4.9-2ubuntu1_all.deb ... 93s Unpacking python3-jupyter-client (7.4.9-2ubuntu1) ... 93s Selecting previously unselected package python3-packaging. 93s Preparing to unpack .../66-python3-packaging_24.0-1_all.deb ... 93s Unpacking python3-packaging (24.0-1) ... 93s Selecting previously unselected package python3-psutil. 93s Preparing to unpack .../67-python3-psutil_5.9.8-2build2_arm64.deb ... 93s Unpacking python3-psutil (5.9.8-2build2) ... 93s Selecting previously unselected package python3-ipykernel. 93s Preparing to unpack .../68-python3-ipykernel_6.29.3-1ubuntu1_all.deb ... 93s Unpacking python3-ipykernel (6.29.3-1ubuntu1) ... 93s Selecting previously unselected package python3-ipython-genutils. 93s Preparing to unpack .../69-python3-ipython-genutils_0.2.0-6_all.deb ... 93s Unpacking python3-ipython-genutils (0.2.0-6) ... 94s Selecting previously unselected package python3-webencodings. 94s Preparing to unpack .../70-python3-webencodings_0.5.1-5_all.deb ... 94s Unpacking python3-webencodings (0.5.1-5) ... 94s Selecting previously unselected package python3-html5lib. 94s Preparing to unpack .../71-python3-html5lib_1.1-6_all.deb ... 94s Unpacking python3-html5lib (1.1-6) ... 94s Selecting previously unselected package python3-bleach. 94s Preparing to unpack .../72-python3-bleach_6.1.0-2_all.deb ... 94s Unpacking python3-bleach (6.1.0-2) ... 94s Selecting previously unselected package python3-soupsieve. 94s Preparing to unpack .../73-python3-soupsieve_2.5-1_all.deb ... 94s Unpacking python3-soupsieve (2.5-1) ... 94s Selecting previously unselected package python3-bs4. 94s Preparing to unpack .../74-python3-bs4_4.12.3-1_all.deb ... 94s Unpacking python3-bs4 (4.12.3-1) ... 94s Selecting previously unselected package python3-defusedxml. 94s Preparing to unpack .../75-python3-defusedxml_0.7.1-2_all.deb ... 94s Unpacking python3-defusedxml (0.7.1-2) ... 94s Selecting previously unselected package python3-jupyterlab-pygments. 94s Preparing to unpack .../76-python3-jupyterlab-pygments_0.2.2-3_all.deb ... 94s Unpacking python3-jupyterlab-pygments (0.2.2-3) ... 94s Selecting previously unselected package python3-mistune. 94s Preparing to unpack .../77-python3-mistune_3.0.2-1_all.deb ... 94s Unpacking python3-mistune (3.0.2-1) ... 94s Selecting previously unselected package python3-fastjsonschema. 94s Preparing to unpack .../78-python3-fastjsonschema_2.19.1-1_all.deb ... 94s Unpacking python3-fastjsonschema (2.19.1-1) ... 94s Selecting previously unselected package python3-nbformat. 94s Preparing to unpack .../79-python3-nbformat_5.9.1-1_all.deb ... 94s Unpacking python3-nbformat (5.9.1-1) ... 94s Selecting previously unselected package python3-nbclient. 94s Preparing to unpack .../80-python3-nbclient_0.8.0-1_all.deb ... 94s Unpacking python3-nbclient (0.8.0-1) ... 94s Selecting previously unselected package python3-pandocfilters. 94s Preparing to unpack .../81-python3-pandocfilters_1.5.1-1_all.deb ... 94s Unpacking python3-pandocfilters (1.5.1-1) ... 94s Selecting previously unselected package python-tinycss2-common. 94s Preparing to unpack .../82-python-tinycss2-common_1.3.0-1_all.deb ... 94s Unpacking python-tinycss2-common (1.3.0-1) ... 95s Selecting previously unselected package python3-tinycss2. 95s Preparing to unpack .../83-python3-tinycss2_1.3.0-1_all.deb ... 95s Unpacking python3-tinycss2 (1.3.0-1) ... 95s Selecting previously unselected package python3-nbconvert. 95s Preparing to unpack .../84-python3-nbconvert_7.16.4-1_all.deb ... 95s Unpacking python3-nbconvert (7.16.4-1) ... 95s Selecting previously unselected package python3-prometheus-client. 95s Preparing to unpack .../85-python3-prometheus-client_0.19.0+ds1-1_all.deb ... 95s Unpacking python3-prometheus-client (0.19.0+ds1-1) ... 95s Selecting previously unselected package python3-send2trash. 95s Preparing to unpack .../86-python3-send2trash_1.8.2-1_all.deb ... 95s Unpacking python3-send2trash (1.8.2-1) ... 95s Selecting previously unselected package python3-notebook. 95s Preparing to unpack .../87-python3-notebook_6.4.12-2.2ubuntu1_all.deb ... 95s Unpacking python3-notebook (6.4.12-2.2ubuntu1) ... 95s Selecting previously unselected package jupyter-notebook. 95s Preparing to unpack .../88-jupyter-notebook_6.4.12-2.2ubuntu1_all.deb ... 95s Unpacking jupyter-notebook (6.4.12-2.2ubuntu1) ... 95s Selecting previously unselected package libjs-sphinxdoc. 95s Preparing to unpack .../89-libjs-sphinxdoc_7.2.6-8_all.deb ... 95s Unpacking libjs-sphinxdoc (7.2.6-8) ... 95s Selecting previously unselected package sphinx-rtd-theme-common. 95s Preparing to unpack .../90-sphinx-rtd-theme-common_2.0.0+dfsg-1_all.deb ... 95s Unpacking sphinx-rtd-theme-common (2.0.0+dfsg-1) ... 95s Selecting previously unselected package python-notebook-doc. 95s Preparing to unpack .../91-python-notebook-doc_6.4.12-2.2ubuntu1_all.deb ... 95s Unpacking python-notebook-doc (6.4.12-2.2ubuntu1) ... 96s Selecting previously unselected package python3-iniconfig. 96s Preparing to unpack .../92-python3-iniconfig_1.1.1-2_all.deb ... 96s Unpacking python3-iniconfig (1.1.1-2) ... 96s Selecting previously unselected package python3-pluggy. 96s Preparing to unpack .../93-python3-pluggy_1.5.0-1_all.deb ... 96s Unpacking python3-pluggy (1.5.0-1) ... 96s Selecting previously unselected package python3-pytest. 96s Preparing to unpack .../94-python3-pytest_7.4.4-1_all.deb ... 96s Unpacking python3-pytest (7.4.4-1) ... 96s Selecting previously unselected package python3-requests-unixsocket. 96s Preparing to unpack .../95-python3-requests-unixsocket_0.3.0-4_all.deb ... 96s Unpacking python3-requests-unixsocket (0.3.0-4) ... 96s Selecting previously unselected package autopkgtest-satdep. 96s Preparing to unpack .../96-1-autopkgtest-satdep.deb ... 96s Unpacking autopkgtest-satdep (0) ... 96s Setting up python3-entrypoints (0.4-2) ... 97s Setting up libjs-jquery-typeahead (2.11.0+dfsg1-3) ... 97s Setting up python3-iniconfig (1.1.1-2) ... 97s Setting up python3-tornado (6.4.1-1) ... 97s Setting up libnorm1t64:arm64 (1.5.9+dfsg-3.1build1) ... 97s Setting up python3-pure-eval (0.2.2-2) ... 97s Setting up python3-send2trash (1.8.2-1) ... 98s Setting up fonts-lato (2.015-1) ... 98s Setting up fonts-mathjax (2.7.9+dfsg-1) ... 98s Setting up libsodium23:arm64 (1.0.18-1build3) ... 98s Setting up python3-setuptools (68.1.2-2ubuntu1) ... 98s Setting up libjs-mathjax (2.7.9+dfsg-1) ... 98s Setting up python3-py (1.11.0-2) ... 98s Setting up libdebuginfod-common (0.191-1) ... 98s Setting up libjs-requirejs-text (2.0.12-1.1) ... 98s Setting up python3-parso (0.8.3-1) ... 99s Setting up python3-defusedxml (0.7.1-2) ... 99s Setting up python3-ipython-genutils (0.2.0-6) ... 99s Setting up python3-asttokens (2.4.1-1) ... 99s Setting up fonts-glyphicons-halflings (1.009~3.4.1+dfsg-3) ... 99s Setting up python3-coverage (7.4.4+dfsg1-0ubuntu2) ... 99s Setting up libjs-moment (2.29.4+ds-1) ... 99s Setting up python3-pandocfilters (1.5.1-1) ... 99s Setting up libjs-requirejs (2.3.6+ds+~2.1.37-1) ... 99s Setting up libjs-es6-promise (4.2.8-12) ... 99s Setting up libjs-text-encoding (0.7.0-5) ... 99s Setting up python3-webencodings (0.5.1-5) ... 100s Setting up python3-platformdirs (4.2.1-1) ... 100s Setting up python3-psutil (5.9.8-2build2) ... 100s Setting up libsource-highlight-common (3.1.9-4.3build1) ... 100s Setting up python3-requests-unixsocket (0.3.0-4) ... 100s Setting up python3-jupyterlab-pygments (0.2.2-3) ... 100s Setting up libpython3.12t64:arm64 (3.12.4-1) ... 100s Setting up libpgm-5.3-0t64:arm64 (5.3.128~dfsg-2.1build1) ... 100s Setting up python3-decorator (5.1.1-5) ... 101s Setting up python3-packaging (24.0-1) ... 101s Setting up python3-wcwidth (0.2.5+dfsg1-1.1ubuntu1) ... 101s Setting up node-jed (1.1.1-4) ... 101s Setting up python3-typeshed (0.0~git20231111.6764465-3) ... 101s Setting up python3-executing (2.0.1-0.1) ... 101s Setting up libjs-xterm (5.3.0-2) ... 101s Setting up python3-nest-asyncio (1.5.4-1) ... 101s Setting up python3-bytecode (0.15.1-3) ... 101s Setting up libjs-codemirror (5.65.0+~cs5.83.9-3) ... 101s Setting up libjs-jed (1.1.1-4) ... 101s Setting up python3-html5lib (1.1-6) ... 102s Setting up libbabeltrace1:arm64 (1.5.11-3build3) ... 102s Setting up python3-pluggy (1.5.0-1) ... 102s Setting up python3-fastjsonschema (2.19.1-1) ... 102s Setting up python3-traitlets (5.14.3-1) ... 102s Setting up python-tinycss2-common (1.3.0-1) ... 102s Setting up python3-argon2 (21.1.0-2build1) ... 102s Setting up python3-dateutil (2.9.0-2) ... 102s Setting up libjs-jquery (3.6.1+dfsg+~3.5.14-1) ... 102s Setting up python3-mistune (3.0.2-1) ... 103s Setting up python3-stack-data (0.6.3-1) ... 103s Setting up python3-soupsieve (2.5-1) ... 103s Setting up fonts-font-awesome (5.0.10+really4.7.0~dfsg-4.1) ... 103s Setting up sphinx-rtd-theme-common (2.0.0+dfsg-1) ... 103s Setting up python3-jupyter-core (5.3.2-2) ... 103s Setting up libjs-bootstrap (3.4.1+dfsg-3) ... 103s Setting up libjs-underscore (1.13.4~dfsg+~1.11.4-3) ... 103s Setting up python3-ptyprocess (0.7.0-5) ... 103s Setting up libjs-marked (4.2.3+ds+~4.0.7-3) ... 103s Setting up python3-prompt-toolkit (3.0.46-1) ... 103s Setting up libdebuginfod1t64:arm64 (0.191-1) ... 103s Setting up python3-tinycss2 (1.3.0-1) ... 104s Setting up libzmq5:arm64 (4.3.5-1build2) ... 104s Setting up python3-jedi (0.19.1+ds1-1) ... 104s Setting up python3-pytest (7.4.4-1) ... 104s Setting up libjs-bootstrap-tour (0.12.0+dfsg-5) ... 104s Setting up libjs-backbone (1.4.1~dfsg+~1.4.15-3) ... 104s Setting up libsource-highlight4t64:arm64 (3.1.9-4.3build1) ... 104s Setting up python3-nbformat (5.9.1-1) ... 104s Setting up python3-bs4 (4.12.3-1) ... 105s Setting up python3-bleach (6.1.0-2) ... 105s Setting up python3-matplotlib-inline (0.1.6-2) ... 105s Setting up python3-comm (0.2.1-1) ... 105s Setting up python3-prometheus-client (0.19.0+ds1-1) ... 105s Setting up gdb (15.0.50.20240403-0ubuntu1) ... 105s Setting up libjs-jquery-ui (1.13.2+dfsg-1) ... 105s Setting up python3-pexpect (4.9-2) ... 106s Setting up python3-zmq (24.0.1-5build1) ... 106s Setting up libjs-sphinxdoc (7.2.6-8) ... 106s Setting up python3-terminado (0.18.1-1) ... 106s Setting up python3-jupyter-client (7.4.9-2ubuntu1) ... 106s Setting up jupyter-core (5.3.2-2) ... 106s Setting up python3-pydevd (2.10.0+ds-10ubuntu1) ... 107s Setting up python3-debugpy (1.8.0+ds-4ubuntu4) ... 107s Setting up python-notebook-doc (6.4.12-2.2ubuntu1) ... 107s Setting up python3-nbclient (0.8.0-1) ... 107s Setting up python3-ipython (8.20.0-1ubuntu1) ... 108s Setting up python3-ipykernel (6.29.3-1ubuntu1) ... 108s Setting up python3-nbconvert (7.16.4-1) ... 108s Setting up python3-notebook (6.4.12-2.2ubuntu1) ... 109s Setting up jupyter-notebook (6.4.12-2.2ubuntu1) ... 109s Setting up autopkgtest-satdep (0) ... 109s Processing triggers for man-db (2.12.1-2) ... 110s Processing triggers for libc-bin (2.39-0ubuntu9) ... 117s (Reading database ... 95089 files and directories currently installed.) 117s Removing autopkgtest-satdep (0) ... 118s autopkgtest [11:39:11]: test pytest: [----------------------- 120s ============================= test session starts ============================== 120s platform linux -- Python 3.12.4, pytest-7.4.4, pluggy-1.5.0 120s rootdir: /tmp/autopkgtest.MsnsbA/build.ybd/src 120s collected 330 items / 5 deselected / 325 selected 120s 121s notebook/auth/tests/test_login.py EE [ 0%] 121s notebook/auth/tests/test_security.py .... [ 1%] 122s notebook/bundler/tests/test_bundler_api.py EEEEE [ 3%] 122s notebook/bundler/tests/test_bundler_tools.py ............. [ 7%] 123s notebook/bundler/tests/test_bundlerextension.py ... [ 8%] 123s notebook/nbconvert/tests/test_nbconvert_handlers.py ssssss [ 10%] 124s notebook/services/api/tests/test_api.py EEE [ 11%] 124s notebook/services/config/tests/test_config_api.py EEE [ 12%] 127s notebook/services/contents/tests/test_contents_api.py EsEEEEEEEEEEssEEsE [ 17%] 137s EEEEEEEEEEEEEEEEEEEEEEEEEsEEEEEEEEEEEssEEsEEEEEEEEEEEEEEEEEEEEEEEEE [ 38%] 137s notebook/services/contents/tests/test_fileio.py ... [ 39%] 137s notebook/services/contents/tests/test_largefilemanager.py . [ 39%] 138s notebook/services/contents/tests/test_manager.py .....s........ss....... [ 46%] 138s ...ss........ [ 50%] 140s notebook/services/kernels/tests/test_kernels_api.py EEEEEEEEEEEE [ 54%] 141s notebook/services/kernelspecs/tests/test_kernelspecs_api.py EEEEEEE [ 56%] 141s notebook/services/nbconvert/tests/test_nbconvert_api.py E [ 56%] 143s notebook/services/sessions/tests/test_sessionmanager.py FFFFFFFFF [ 59%] 145s notebook/services/sessions/tests/test_sessions_api.py EEEEEEEEEEEEEEEEEE [ 64%] 146s EEEE [ 66%] 147s notebook/terminal/tests/test_terminals_api.py EEEEEEEE [ 68%] 147s notebook/tests/test_config_manager.py . [ 68%] 147s notebook/tests/test_files.py EEEEE [ 70%] 148s notebook/tests/test_gateway.py EEEEEE [ 72%] 148s notebook/tests/test_i18n.py . [ 72%] 148s notebook/tests/test_log.py . [ 72%] 149s notebook/tests/test_nbextensions.py ................................... [ 83%] 153s notebook/tests/test_notebookapp.py FFFFFFFFF........F.EEEEEEE [ 91%] 153s notebook/tests/test_paths.py ..E [ 92%] 153s notebook/tests/test_serialize.py .. [ 93%] 154s notebook/tests/test_serverextensions.py ...FF [ 94%] 154s notebook/tests/test_traittypes.py ........... [ 98%] 154s notebook/tests/test_utils.py F...s [ 99%] 155s notebook/tree/tests/test_tree_handler.py E [100%] 155s 155s ==================================== ERRORS ==================================== 155s __________________ ERROR at setup of LoginTest.test_next_bad ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of LoginTest.test_next_ok ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of BundleAPITest.test_bundler_import_error ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s """Make a test notebook. Borrowed from nbconvert test. Assumes the class 155s teardown will clean it up in the end.""" 155s > super().setup_class() 155s 155s notebook/bundler/tests/test_bundler_api.py:27: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of BundleAPITest.test_bundler_invoke ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s """Make a test notebook. Borrowed from nbconvert test. Assumes the class 155s teardown will clean it up in the end.""" 155s > super().setup_class() 155s 155s notebook/bundler/tests/test_bundler_api.py:27: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of BundleAPITest.test_bundler_not_enabled ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s """Make a test notebook. Borrowed from nbconvert test. Assumes the class 155s teardown will clean it up in the end.""" 155s > super().setup_class() 155s 155s notebook/bundler/tests/test_bundler_api.py:27: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of BundleAPITest.test_missing_bundler_arg ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s """Make a test notebook. Borrowed from nbconvert test. Assumes the class 155s teardown will clean it up in the end.""" 155s > super().setup_class() 155s 155s notebook/bundler/tests/test_bundler_api.py:27: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of BundleAPITest.test_notebook_not_found ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s """Make a test notebook. Borrowed from nbconvert test. Assumes the class 155s teardown will clean it up in the end.""" 155s > super().setup_class() 155s 155s notebook/bundler/tests/test_bundler_api.py:27: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of APITest.test_get_spec ____________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of APITest.test_get_status ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_no_track_activity _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of APITest.test_create_retrieve_config _____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of APITest.test_get_unknown __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________________ ERROR at setup of APITest.test_modify _____________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of APITest.test_checkpoints __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of APITest.test_checkpoints_separate_root ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________________ ERROR at setup of APITest.test_copy ______________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_copy_400_hidden ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of APITest.test_copy_copy ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________________ ERROR at setup of APITest.test_copy_dir_400 __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of APITest.test_copy_path ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________________ ERROR at setup of APITest.test_copy_put_400 __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of APITest.test_copy_put_400_hidden ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_create_untitled ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of APITest.test_create_untitled_txt ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_delete_hidden_dir _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of APITest.test_delete_hidden_file _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_file_checkpoints ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_get_404_hidden _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________________ ERROR at setup of APITest.test_get_bad_type __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of APITest.test_get_binary_file_contents ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of APITest.test_get_contents_no_such_file ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of APITest.test_get_dir_no_content _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_get_nb_contents ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_get_nb_invalid _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_get_nb_no_content _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of APITest.test_get_text_file_contents _____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of APITest.test_list_dirs ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of APITest.test_list_nonexistant_dir ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_list_notebooks _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________________ ERROR at setup of APITest.test_mkdir _____________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_mkdir_hidden_400 ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_mkdir_untitled _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________________ ERROR at setup of APITest.test_rename _____________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_rename_400_hidden _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_rename_existing ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________________ ERROR at setup of APITest.test_save ______________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________________ ERROR at setup of APITest.test_upload _____________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of APITest.test_upload_b64 ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of APITest.test_upload_txt ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_upload_txt_hidden _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of APITest.test_upload_v2 ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______ ERROR at setup of GenericFileCheckpointsAPITest.test_checkpoints _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _ ERROR at setup of GenericFileCheckpointsAPITest.test_checkpoints_separate_root _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __ ERROR at setup of GenericFileCheckpointsAPITest.test_config_did_something ___ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of GenericFileCheckpointsAPITest.test_copy ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_copy_400_hidden _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of GenericFileCheckpointsAPITest.test_copy_copy ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______ ERROR at setup of GenericFileCheckpointsAPITest.test_copy_dir_400 _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of GenericFileCheckpointsAPITest.test_copy_path ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______ ERROR at setup of GenericFileCheckpointsAPITest.test_copy_put_400 _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___ ERROR at setup of GenericFileCheckpointsAPITest.test_copy_put_400_hidden ___ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_create_untitled _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___ ERROR at setup of GenericFileCheckpointsAPITest.test_create_untitled_txt ___ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____ ERROR at setup of GenericFileCheckpointsAPITest.test_delete_hidden_dir ____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___ ERROR at setup of GenericFileCheckpointsAPITest.test_delete_hidden_file ____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____ ERROR at setup of GenericFileCheckpointsAPITest.test_file_checkpoints _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_get_404_hidden ______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______ ERROR at setup of GenericFileCheckpointsAPITest.test_get_bad_type _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _ ERROR at setup of GenericFileCheckpointsAPITest.test_get_binary_file_contents _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _ ERROR at setup of GenericFileCheckpointsAPITest.test_get_contents_no_such_file _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___ ERROR at setup of GenericFileCheckpointsAPITest.test_get_dir_no_content ____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_get_nb_contents _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_get_nb_invalid ______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____ ERROR at setup of GenericFileCheckpointsAPITest.test_get_nb_no_content ____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _ ERROR at setup of GenericFileCheckpointsAPITest.test_get_text_file_contents __ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of GenericFileCheckpointsAPITest.test_list_dirs ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __ ERROR at setup of GenericFileCheckpointsAPITest.test_list_nonexistant_dir ___ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_list_notebooks ______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of GenericFileCheckpointsAPITest.test_mkdir __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____ ERROR at setup of GenericFileCheckpointsAPITest.test_mkdir_hidden_400 _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_mkdir_untitled ______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of GenericFileCheckpointsAPITest.test_rename __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____ ERROR at setup of GenericFileCheckpointsAPITest.test_rename_400_hidden ____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of GenericFileCheckpointsAPITest.test_rename_existing _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of GenericFileCheckpointsAPITest.test_save ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of GenericFileCheckpointsAPITest.test_upload __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______ ERROR at setup of GenericFileCheckpointsAPITest.test_upload_b64 ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______ ERROR at setup of GenericFileCheckpointsAPITest.test_upload_txt ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____ ERROR at setup of GenericFileCheckpointsAPITest.test_upload_txt_hidden ____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of GenericFileCheckpointsAPITest.test_upload_v2 ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of KernelAPITest.test_connections _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of KernelAPITest.test_default_kernel ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of KernelAPITest.test_kernel_handler ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of KernelAPITest.test_main_kernel_handler ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of KernelAPITest.test_no_kernels ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of AsyncKernelAPITest.test_connections _____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncKernelAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/kernels/tests/test_kernels_api.py:206: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of AsyncKernelAPITest.test_default_kernel ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncKernelAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/kernels/tests/test_kernels_api.py:206: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of AsyncKernelAPITest.test_kernel_handler ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncKernelAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/kernels/tests/test_kernels_api.py:206: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of AsyncKernelAPITest.test_main_kernel_handler _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncKernelAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/kernels/tests/test_kernels_api.py:206: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of AsyncKernelAPITest.test_no_kernels _____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncKernelAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/kernels/tests/test_kernels_api.py:206: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of KernelFilterTest.test_config ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of KernelCullingTest.test_culling _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of APITest.test_get_kernel_resource_file ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of APITest.test_get_kernelspec _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of APITest.test_get_kernelspec_spaces _____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of APITest.test_get_nonexistant_kernelspec ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of APITest.test_get_nonexistant_resource ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______________ ERROR at setup of APITest.test_list_kernelspecs ________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of APITest.test_list_kernelspecs_bad ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________________ ERROR at setup of APITest.test_list_formats __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________________ ERROR at setup of SessionAPITest.test_create _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of SessionAPITest.test_create_console_session _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of SessionAPITest.test_create_deprecated ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of SessionAPITest.test_create_file_session ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of SessionAPITest.test_create_with_kernel_id __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________________ ERROR at setup of SessionAPITest.test_delete _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of SessionAPITest.test_modify_kernel_id ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of SessionAPITest.test_modify_kernel_name ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of SessionAPITest.test_modify_path _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of SessionAPITest.test_modify_path_deprecated _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of SessionAPITest.test_modify_type _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of AsyncSessionAPITest.test_create _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______ ERROR at setup of AsyncSessionAPITest.test_create_console_session _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of AsyncSessionAPITest.test_create_deprecated _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of AsyncSessionAPITest.test_create_file_session ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______ ERROR at setup of AsyncSessionAPITest.test_create_with_kernel_id _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of AsyncSessionAPITest.test_delete _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of AsyncSessionAPITest.test_modify_kernel_id __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of AsyncSessionAPITest.test_modify_kernel_name _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of AsyncSessionAPITest.test_modify_path ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______ ERROR at setup of AsyncSessionAPITest.test_modify_path_deprecated _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of AsyncSessionAPITest.test_modify_type ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s if not async_testing_enabled: # Can be removed once jupyter_client >= 6.1 is required. 155s raise SkipTest("AsyncSessionAPITest tests skipped due to down-level jupyter_client!") 155s > super().setup_class() 155s 155s notebook/services/sessions/tests/test_sessions_api.py:274: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of TerminalAPITest.test_create_terminal ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________ ERROR at setup of TerminalAPITest.test_create_terminal_via_get ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______ ERROR at setup of TerminalAPITest.test_create_terminal_with_name _______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of TerminalAPITest.test_no_terminals ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of TerminalAPITest.test_terminal_handler ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of TerminalAPITest.test_terminal_root_handler _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of TerminalCullingTest.test_config _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of TerminalCullingTest.test_culling ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of FilesTest.test_contents_manager _______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of FilesTest.test_download ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ________________ ERROR at setup of FilesTest.test_hidden_files _________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____________ ERROR at setup of FilesTest.test_old_files_redirect ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________________ ERROR at setup of FilesTest.test_view_html __________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of TestGateway.test_gateway_class_mappings ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s GatewayClient.clear_instance() 155s > super().setup_class() 155s 155s notebook/tests/test_gateway.py:138: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of TestGateway.test_gateway_get_kernelspecs __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s GatewayClient.clear_instance() 155s > super().setup_class() 155s 155s notebook/tests/test_gateway.py:138: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _______ ERROR at setup of TestGateway.test_gateway_get_named_kernelspec ________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s GatewayClient.clear_instance() 155s > super().setup_class() 155s 155s notebook/tests/test_gateway.py:138: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of TestGateway.test_gateway_kernel_lifecycle __________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s GatewayClient.clear_instance() 155s > super().setup_class() 155s 155s notebook/tests/test_gateway.py:138: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of TestGateway.test_gateway_options ______________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s GatewayClient.clear_instance() 155s > super().setup_class() 155s 155s notebook/tests/test_gateway.py:138: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of TestGateway.test_gateway_session_lifecycle _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s GatewayClient.clear_instance() 155s > super().setup_class() 155s 155s notebook/tests/test_gateway.py:138: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _________ ERROR at setup of NotebookAppTests.test_list_running_servers _________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________ ERROR at setup of NotebookAppTests.test_log_json_default ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s __________ ERROR at setup of NotebookAppTests.test_validate_log_json ___________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___ ERROR at setup of NotebookUnixSocketTests.test_list_running_sock_servers ___ 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def connect(self): 155s sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 155s sock.settimeout(self.timeout) 155s socket_path = unquote(urlparse(self.unix_socket_url).netloc) 155s > sock.connect(socket_path) 155s E FileNotFoundError: [Errno 2] No such file or directory 155s 155s /usr/lib/python3/dist-packages/requests_unixsocket/adapters.py:36: FileNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None 155s proxies = OrderedDict({'no': '127.0.0.1,127.0.1.1,login.ubuntu.com,localhost,localdomain,novalocal,internal,archive.ubuntu.com,p...,objectstorage.prodstack5.canonical.com', 'https': 'http://squid.internal:3128', 'http': 'http://squid.internal:3128'}) 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:470: in increment 155s raise reraise(type(error), error, _stacktrace) 155s /usr/lib/python3/dist-packages/urllib3/util/util.py:38: in reraise 155s raise value.with_traceback(tb) 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: in urlopen 155s response = self._make_request( 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def connect(self): 155s sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 155s sock.settimeout(self.timeout) 155s socket_path = unquote(urlparse(self.unix_socket_url).netloc) 155s > sock.connect(socket_path) 155s E urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) 155s 155s /usr/lib/python3/dist-packages/requests_unixsocket/adapters.py:36: ProtocolError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:242: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests_unixsocket/__init__.py:51: in get 155s return request('get', url, **kwargs) 155s /usr/lib/python3/dist-packages/requests_unixsocket/__init__.py:46: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None 155s proxies = OrderedDict({'no': '127.0.0.1,127.0.1.1,login.ubuntu.com,localhost,localdomain,novalocal,internal,archive.ubuntu.com,p...,objectstorage.prodstack5.canonical.com', 'https': 'http://squid.internal:3128', 'http': 'http://squid.internal:3128'}) 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s > raise ConnectionError(err, request=request) 155s E requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:501: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ______________ ERROR at setup of NotebookUnixSocketTests.test_run ______________ 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def connect(self): 155s sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 155s sock.settimeout(self.timeout) 155s socket_path = unquote(urlparse(self.unix_socket_url).netloc) 155s > sock.connect(socket_path) 155s E FileNotFoundError: [Errno 2] No such file or directory 155s 155s /usr/lib/python3/dist-packages/requests_unixsocket/adapters.py:36: FileNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None 155s proxies = OrderedDict({'no': '127.0.0.1,127.0.1.1,login.ubuntu.com,localhost,localdomain,novalocal,internal,archive.ubuntu.com,p...,objectstorage.prodstack5.canonical.com', 'https': 'http://squid.internal:3128', 'http': 'http://squid.internal:3128'}) 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:470: in increment 155s raise reraise(type(error), error, _stacktrace) 155s /usr/lib/python3/dist-packages/urllib3/util/util.py:38: in reraise 155s raise value.with_traceback(tb) 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: in urlopen 155s response = self._make_request( 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def connect(self): 155s sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 155s sock.settimeout(self.timeout) 155s socket_path = unquote(urlparse(self.unix_socket_url).netloc) 155s > sock.connect(socket_path) 155s E urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) 155s 155s /usr/lib/python3/dist-packages/requests_unixsocket/adapters.py:36: ProtocolError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:242: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests_unixsocket/__init__.py:51: in get 155s return request('get', url, **kwargs) 155s /usr/lib/python3/dist-packages/requests_unixsocket/__init__.py:46: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None 155s proxies = OrderedDict({'no': '127.0.0.1,127.0.1.1,login.ubuntu.com,localhost,localdomain,novalocal,internal,archive.ubuntu.com,p...,objectstorage.prodstack5.canonical.com', 'https': 'http://squid.internal:3128', 'http': 'http://squid.internal:3128'}) 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s > raise ConnectionError(err, request=request) 155s E requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:501: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of NotebookAppJSONLoggingTests.test_log_json_enabled ______ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s > super().setup_class() 155s 155s notebook/tests/test_notebookapp.py:212: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s _____ ERROR at setup of NotebookAppJSONLoggingTests.test_validate_log_json _____ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s > super().setup_class() 155s 155s notebook/tests/test_notebookapp.py:212: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:198: in setup_class 155s cls.wait_until_alive() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ____________ ERROR at setup of RedirectTestCase.test_trailing_slash ____________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s ___________________ ERROR at setup of TreeTest.test_redirect ___________________ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s > sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 155s raise err 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s address = ('localhost', 12341), timeout = None, source_address = None 155s socket_options = [(6, 1, 1)] 155s 155s def create_connection( 155s address: tuple[str, int], 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s source_address: tuple[str, int] | None = None, 155s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 155s ) -> socket.socket: 155s """Connect to *address* and return the socket object. 155s 155s Convenience function. Connect to *address* (a 2-tuple ``(host, 155s port)``) and return the socket object. Passing the optional 155s *timeout* parameter will set the timeout on the socket instance 155s before attempting to connect. If no *timeout* is supplied, the 155s global default timeout setting returned by :func:`socket.getdefaulttimeout` 155s is used. If *source_address* is set it must be a tuple of (host, port) 155s for the socket to bind as a source address before making the connection. 155s An host of '' or port 0 tells the OS to use the default. 155s """ 155s 155s host, port = address 155s if host.startswith("["): 155s host = host.strip("[]") 155s err = None 155s 155s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 155s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 155s # The original create_connection function always returns all records. 155s family = allowed_gai_family() 155s 155s try: 155s host.encode("idna") 155s except UnicodeError: 155s raise LocationParseError(f"'{host}', label empty or too long") from None 155s 155s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 155s af, socktype, proto, canonname, sa = res 155s sock = None 155s try: 155s sock = socket.socket(af, socktype, proto) 155s 155s # If provided, set socket level options before connecting. 155s _set_socket_options(sock, socket_options) 155s 155s if timeout is not _DEFAULT_TIMEOUT: 155s sock.settimeout(timeout) 155s if source_address: 155s sock.bind(source_address) 155s > sock.connect(sa) 155s E ConnectionRefusedError: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s method = 'GET', url = '/a%40b/api/contents', body = None 155s headers = {'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 155s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s redirect = False, assert_same_host = False 155s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 155s release_conn = False, chunked = False, body_pos = None, preload_content = False 155s decode_content = False, response_kw = {} 155s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/a%40b/api/contents', query=None, fragment=None) 155s destination_scheme = None, conn = None, release_this_conn = True 155s http_tunnel_required = False, err = None, clean_exit = False 155s 155s def urlopen( # type: ignore[override] 155s self, 155s method: str, 155s url: str, 155s body: _TYPE_BODY | None = None, 155s headers: typing.Mapping[str, str] | None = None, 155s retries: Retry | bool | int | None = None, 155s redirect: bool = True, 155s assert_same_host: bool = True, 155s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 155s pool_timeout: int | None = None, 155s release_conn: bool | None = None, 155s chunked: bool = False, 155s body_pos: _TYPE_BODY_POSITION | None = None, 155s preload_content: bool = True, 155s decode_content: bool = True, 155s **response_kw: typing.Any, 155s ) -> BaseHTTPResponse: 155s """ 155s Get a connection from the pool and perform an HTTP request. This is the 155s lowest level call for making a request, so you'll need to specify all 155s the raw details. 155s 155s .. note:: 155s 155s More commonly, it's appropriate to use a convenience method 155s such as :meth:`request`. 155s 155s .. note:: 155s 155s `release_conn` will only behave as expected if 155s `preload_content=False` because we want to make 155s `preload_content=False` the default behaviour someday soon without 155s breaking backwards compatibility. 155s 155s :param method: 155s HTTP request method (such as GET, POST, PUT, etc.) 155s 155s :param url: 155s The URL to perform the request on. 155s 155s :param body: 155s Data to send in the request body, either :class:`str`, :class:`bytes`, 155s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 155s 155s :param headers: 155s Dictionary of custom headers to send, such as User-Agent, 155s If-None-Match, etc. If None, pool headers are used. If provided, 155s these headers completely replace any pool-specific headers. 155s 155s :param retries: 155s Configure the number of retries to allow before raising a 155s :class:`~urllib3.exceptions.MaxRetryError` exception. 155s 155s Pass ``None`` to retry until you receive a response. Pass a 155s :class:`~urllib3.util.retry.Retry` object for fine-grained control 155s over different types of retries. 155s Pass an integer number to retry connection errors that many times, 155s but no other types of errors. Pass zero to never retry. 155s 155s If ``False``, then retries are disabled and any exception is raised 155s immediately. Also, instead of raising a MaxRetryError on redirects, 155s the redirect response will be returned. 155s 155s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 155s 155s :param redirect: 155s If True, automatically handle redirects (status codes 301, 302, 155s 303, 307, 308). Each redirect counts as a retry. Disabling retries 155s will disable redirect, too. 155s 155s :param assert_same_host: 155s If ``True``, will make sure that the host of the pool requests is 155s consistent else will raise HostChangedError. When ``False``, you can 155s use the pool on an HTTP proxy and request foreign hosts. 155s 155s :param timeout: 155s If specified, overrides the default timeout for this one 155s request. It may be a float (in seconds) or an instance of 155s :class:`urllib3.util.Timeout`. 155s 155s :param pool_timeout: 155s If set and the pool is set to block=True, then this method will 155s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 155s connection is available within the time period. 155s 155s :param bool preload_content: 155s If True, the response's body will be preloaded into memory. 155s 155s :param bool decode_content: 155s If True, will attempt to decode the body based on the 155s 'content-encoding' header. 155s 155s :param release_conn: 155s If False, then the urlopen call will not release the connection 155s back into the pool once a response is received (but will release if 155s you read the entire contents of the response such as when 155s `preload_content=True`). This is useful if you're not preloading 155s the response's content immediately. You will need to call 155s ``r.release_conn()`` on the response ``r`` to return the connection 155s back into the pool. If None, it takes the value of ``preload_content`` 155s which defaults to ``True``. 155s 155s :param bool chunked: 155s If True, urllib3 will send the body using chunked transfer 155s encoding. Otherwise, urllib3 will send the body using the standard 155s content-length form. Defaults to False. 155s 155s :param int body_pos: 155s Position to seek to in file-like body in the event of a retry or 155s redirect. Typically this won't need to be set because urllib3 will 155s auto-populate the value when needed. 155s """ 155s parsed_url = parse_url(url) 155s destination_scheme = parsed_url.scheme 155s 155s if headers is None: 155s headers = self.headers 155s 155s if not isinstance(retries, Retry): 155s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 155s 155s if release_conn is None: 155s release_conn = preload_content 155s 155s # Check host 155s if assert_same_host and not self.is_same_host(url): 155s raise HostChangedError(self, url, retries) 155s 155s # Ensure that the URL we're connecting to is properly encoded 155s if url.startswith("/"): 155s url = to_str(_encode_target(url)) 155s else: 155s url = to_str(parsed_url.url) 155s 155s conn = None 155s 155s # Track whether `conn` needs to be released before 155s # returning/raising/recursing. Update this variable if necessary, and 155s # leave `release_conn` constant throughout the function. That way, if 155s # the function recurses, the original value of `release_conn` will be 155s # passed down into the recursive call, and its value will be respected. 155s # 155s # See issue #651 [1] for details. 155s # 155s # [1] 155s release_this_conn = release_conn 155s 155s http_tunnel_required = connection_requires_http_tunnel( 155s self.proxy, self.proxy_config, destination_scheme 155s ) 155s 155s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 155s # have to copy the headers dict so we can safely change it without those 155s # changes being reflected in anyone else's copy. 155s if not http_tunnel_required: 155s headers = headers.copy() # type: ignore[attr-defined] 155s headers.update(self.proxy_headers) # type: ignore[union-attr] 155s 155s # Must keep the exception bound to a separate variable or else Python 3 155s # complains about UnboundLocalError. 155s err = None 155s 155s # Keep track of whether we cleanly exited the except block. This 155s # ensures we do proper cleanup in finally. 155s clean_exit = False 155s 155s # Rewind body position, if needed. Record current position 155s # for future rewinds in the event of a redirect/retry. 155s body_pos = set_file_position(body, body_pos) 155s 155s try: 155s # Request a connection from the queue. 155s timeout_obj = self._get_timeout(timeout) 155s conn = self._get_conn(timeout=pool_timeout) 155s 155s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 155s 155s # Is this a closed/new connection that requires CONNECT tunnelling? 155s if self.proxy is not None and http_tunnel_required and conn.is_closed: 155s try: 155s self._prepare_proxy(conn) 155s except (BaseSSLError, OSError, SocketTimeout) as e: 155s self._raise_timeout( 155s err=e, url=self.proxy.url, timeout_value=conn.timeout 155s ) 155s raise 155s 155s # If we're going to release the connection in ``finally:``, then 155s # the response doesn't need to know about the connection. Otherwise 155s # it will also try to release it and we'll have a double-release 155s # mess. 155s response_conn = conn if not release_conn else None 155s 155s # Make the request on the HTTPConnection object 155s > response = self._make_request( 155s conn, 155s method, 155s url, 155s timeout=timeout_obj, 155s body=body, 155s headers=headers, 155s chunked=chunked, 155s retries=retries, 155s response_conn=response_conn, 155s preload_content=preload_content, 155s decode_content=decode_content, 155s **response_kw, 155s ) 155s 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:497: in _make_request 155s conn.request( 155s /usr/lib/python3/dist-packages/urllib3/connection.py:395: in request 155s self.endheaders() 155s /usr/lib/python3.12/http/client.py:1331: in endheaders 155s self._send_output(message_body, encode_chunked=encode_chunked) 155s /usr/lib/python3.12/http/client.py:1091: in _send_output 155s self.send(msg) 155s /usr/lib/python3.12/http/client.py:1035: in send 155s self.connect() 155s /usr/lib/python3/dist-packages/urllib3/connection.py:243: in connect 155s self.sock = self._new_conn() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _new_conn(self) -> socket.socket: 155s """Establish a socket connection and set nodelay settings on it. 155s 155s :return: New socket connection. 155s """ 155s try: 155s sock = connection.create_connection( 155s (self._dns_host, self.port), 155s self.timeout, 155s source_address=self.source_address, 155s socket_options=self.socket_options, 155s ) 155s except socket.gaierror as e: 155s raise NameResolutionError(self.host, self, e) from e 155s except SocketTimeout as e: 155s raise ConnectTimeoutError( 155s self, 155s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 155s ) from e 155s 155s except OSError as e: 155s > raise NewConnectionError( 155s self, f"Failed to establish a new connection: {e}" 155s ) from e 155s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 155s 155s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s > resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:486: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 155s retries = retries.increment( 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 155s method = 'GET', url = '/a%40b/api/contents', response = None 155s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 155s _pool = 155s _stacktrace = 155s 155s def increment( 155s self, 155s method: str | None = None, 155s url: str | None = None, 155s response: BaseHTTPResponse | None = None, 155s error: Exception | None = None, 155s _pool: ConnectionPool | None = None, 155s _stacktrace: TracebackType | None = None, 155s ) -> Retry: 155s """Return a new Retry object with incremented retry counters. 155s 155s :param response: A response object, or None, if the server did not 155s return a response. 155s :type response: :class:`~urllib3.response.BaseHTTPResponse` 155s :param Exception error: An error encountered during the request, or 155s None if the response was received successfully. 155s 155s :return: A new ``Retry`` object. 155s """ 155s if self.total is False and error: 155s # Disabled, indicate to re-raise the error. 155s raise reraise(type(error), error, _stacktrace) 155s 155s total = self.total 155s if total is not None: 155s total -= 1 155s 155s connect = self.connect 155s read = self.read 155s redirect = self.redirect 155s status_count = self.status 155s other = self.other 155s cause = "unknown" 155s status = None 155s redirect_location = None 155s 155s if error and self._is_connection_error(error): 155s # Connect retry? 155s if connect is False: 155s raise reraise(type(error), error, _stacktrace) 155s elif connect is not None: 155s connect -= 1 155s 155s elif error and self._is_read_error(error): 155s # Read retry? 155s if read is False or method is None or not self._is_method_retryable(method): 155s raise reraise(type(error), error, _stacktrace) 155s elif read is not None: 155s read -= 1 155s 155s elif error: 155s # Other retry? 155s if other is not None: 155s other -= 1 155s 155s elif response and response.get_redirect_location(): 155s # Redirect retry? 155s if redirect is not None: 155s redirect -= 1 155s cause = "too many redirects" 155s response_redirect_location = response.get_redirect_location() 155s if response_redirect_location: 155s redirect_location = response_redirect_location 155s status = response.status 155s 155s else: 155s # Incrementing because of a server error like a 500 in 155s # status_forcelist and the given method is in the allowed_methods 155s cause = ResponseError.GENERIC_ERROR 155s if response and response.status: 155s if status_count is not None: 155s status_count -= 1 155s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 155s status = response.status 155s 155s history = self.history + ( 155s RequestHistory(method, url, error, status, redirect_location), 155s ) 155s 155s new_retry = self.new( 155s total=total, 155s connect=connect, 155s read=read, 155s redirect=redirect, 155s status=status_count, 155s other=other, 155s history=history, 155s ) 155s 155s if new_retry.is_exhausted(): 155s reason = error or ResponseError(cause) 155s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 155s E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/urllib3/util/retry.py:515: MaxRetryError 155s 155s During handling of the above exception, another exception occurred: 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s > cls.fetch_url(url) 155s 155s notebook/tests/launchnotebook.py:53: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s notebook/tests/launchnotebook.py:82: in fetch_url 155s return requests.get(url) 155s /usr/lib/python3/dist-packages/requests/api.py:73: in get 155s return request("get", url, params=params, **kwargs) 155s /usr/lib/python3/dist-packages/requests/api.py:59: in request 155s return session.request(method=method, url=url, **kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 155s resp = self.send(prep, **send_kwargs) 155s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 155s r = adapter.send(request, **kwargs) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s request = , stream = False 155s timeout = Timeout(connect=None, read=None, total=None), verify = True 155s cert = None, proxies = OrderedDict() 155s 155s def send( 155s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 155s ): 155s """Sends PreparedRequest object. Returns Response object. 155s 155s :param request: The :class:`PreparedRequest ` being sent. 155s :param stream: (optional) Whether to stream the request content. 155s :param timeout: (optional) How long to wait for the server to send 155s data before giving up, as a float, or a :ref:`(connect timeout, 155s read timeout) ` tuple. 155s :type timeout: float or tuple or urllib3 Timeout object 155s :param verify: (optional) Either a boolean, in which case it controls whether 155s we verify the server's TLS certificate, or a string, in which case it 155s must be a path to a CA bundle to use 155s :param cert: (optional) Any user-provided SSL certificate to be trusted. 155s :param proxies: (optional) The proxies dictionary to apply to the request. 155s :rtype: requests.Response 155s """ 155s 155s try: 155s conn = self.get_connection(request.url, proxies) 155s except LocationValueError as e: 155s raise InvalidURL(e, request=request) 155s 155s self.cert_verify(conn, request.url, verify, cert) 155s url = self.request_url(request, proxies) 155s self.add_headers( 155s request, 155s stream=stream, 155s timeout=timeout, 155s verify=verify, 155s cert=cert, 155s proxies=proxies, 155s ) 155s 155s chunked = not (request.body is None or "Content-Length" in request.headers) 155s 155s if isinstance(timeout, tuple): 155s try: 155s connect, read = timeout 155s timeout = TimeoutSauce(connect=connect, read=read) 155s except ValueError: 155s raise ValueError( 155s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 155s f"or a single float to set both timeouts to the same value." 155s ) 155s elif isinstance(timeout, TimeoutSauce): 155s pass 155s else: 155s timeout = TimeoutSauce(connect=timeout, read=timeout) 155s 155s try: 155s resp = conn.urlopen( 155s method=request.method, 155s url=url, 155s body=request.body, 155s headers=request.headers, 155s redirect=False, 155s assert_same_host=False, 155s preload_content=False, 155s decode_content=False, 155s retries=self.max_retries, 155s timeout=timeout, 155s chunked=chunked, 155s ) 155s 155s except (ProtocolError, OSError) as err: 155s raise ConnectionError(err, request=request) 155s 155s except MaxRetryError as e: 155s if isinstance(e.reason, ConnectTimeoutError): 155s # TODO: Remove this in 3.0.0: see #2811 155s if not isinstance(e.reason, NewConnectionError): 155s raise ConnectTimeout(e, request=request) 155s 155s if isinstance(e.reason, ResponseError): 155s raise RetryError(e, request=request) 155s 155s if isinstance(e.reason, _ProxyError): 155s raise ProxyError(e, request=request) 155s 155s if isinstance(e.reason, _SSLError): 155s # This branch is for urllib3 v1.22 and later. 155s raise SSLError(e, request=request) 155s 155s > raise ConnectionError(e, request=request) 155s E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=12341): Max retries exceeded with url: /a%40b/api/contents (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 155s 155s /usr/lib/python3/dist-packages/requests/adapters.py:519: ConnectionError 155s 155s The above exception was the direct cause of the following exception: 155s 155s cls = 155s 155s @classmethod 155s def setup_class(cls): 155s cls.tmp_dir = TemporaryDirectory() 155s def tmp(*parts): 155s path = os.path.join(cls.tmp_dir.name, *parts) 155s try: 155s os.makedirs(path) 155s except OSError as e: 155s if e.errno != errno.EEXIST: 155s raise 155s return path 155s 155s cls.home_dir = tmp('home') 155s data_dir = cls.data_dir = tmp('data') 155s config_dir = cls.config_dir = tmp('config') 155s runtime_dir = cls.runtime_dir = tmp('runtime') 155s cls.notebook_dir = tmp('notebooks') 155s cls.env_patch = patch.dict('os.environ', cls.get_patch_env()) 155s cls.env_patch.start() 155s # Patch systemwide & user-wide data & config directories, to isolate 155s # the tests from oddities of the local setup. But leave Python env 155s # locations alone, so data files for e.g. nbconvert are accessible. 155s # If this isolation isn't sufficient, you may need to run the tests in 155s # a virtualenv or conda env. 155s cls.path_patch = patch.multiple( 155s jupyter_core.paths, 155s SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], 155s SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], 155s ) 155s cls.path_patch.start() 155s 155s config = cls.config or Config() 155s config.NotebookNotary.db_file = ':memory:' 155s 155s cls.token = hexlify(os.urandom(4)).decode('ascii') 155s 155s started = Event() 155s def start_thread(): 155s try: 155s bind_args = cls.get_bind_args() 155s app = cls.notebook = NotebookApp( 155s port_retries=0, 155s open_browser=False, 155s config_dir=cls.config_dir, 155s data_dir=cls.data_dir, 155s runtime_dir=cls.runtime_dir, 155s notebook_dir=cls.notebook_dir, 155s base_url=cls.url_prefix, 155s config=config, 155s allow_root=True, 155s token=cls.token, 155s **bind_args 155s ) 155s if "asyncio" in sys.modules: 155s app._init_asyncio_patch() 155s import asyncio 155s 155s asyncio.set_event_loop(asyncio.new_event_loop()) 155s # Patch the current loop in order to match production 155s # behavior 155s import nest_asyncio 155s 155s nest_asyncio.apply() 155s # don't register signal handler during tests 155s app.init_signal = lambda : None 155s # clear log handlers and propagate to root for nose to capture it 155s # needs to be redone after initialize, which reconfigures logging 155s app.log.propagate = True 155s app.log.handlers = [] 155s app.initialize(argv=cls.get_argv()) 155s app.log.propagate = True 155s app.log.handlers = [] 155s loop = IOLoop.current() 155s loop.add_callback(started.set) 155s app.start() 155s finally: 155s # set the event, so failure to start doesn't cause a hang 155s started.set() 155s app.session_manager.close() 155s cls.notebook_thread = Thread(target=start_thread) 155s cls.notebook_thread.daemon = True 155s cls.notebook_thread.start() 155s started.wait() 155s > cls.wait_until_alive() 155s 155s notebook/tests/launchnotebook.py:198: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s cls = 155s 155s @classmethod 155s def wait_until_alive(cls): 155s """Wait for the server to be alive""" 155s url = cls.base_url() + 'api/contents' 155s for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): 155s try: 155s cls.fetch_url(url) 155s except ModuleNotFoundError as error: 155s # Errors that should be immediately thrown back to caller 155s raise error 155s except Exception as e: 155s if not cls.notebook_thread.is_alive(): 155s > raise RuntimeError("The notebook server failed to start") from e 155s E RuntimeError: The notebook server failed to start 155s 155s notebook/tests/launchnotebook.py:59: RuntimeError 155s =================================== FAILURES =================================== 155s __________________ TestSessionManager.test_bad_delete_session __________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s ___________________ TestSessionManager.test_bad_get_session ____________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s __________________ TestSessionManager.test_bad_update_session __________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s ____________________ TestSessionManager.test_delete_session ____________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s _____________________ TestSessionManager.test_get_session ______________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s _______________ TestSessionManager.test_get_session_dead_kernel ________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s ____________________ TestSessionManager.test_list_sessions _____________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s ______________ TestSessionManager.test_list_sessions_dead_kernel _______________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s ____________________ TestSessionManager.test_update_session ____________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:336: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.services.contents.manager.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def setUp(self): 155s > self.sm = SessionManager( 155s kernel_manager=DummyMKM(), 155s contents_manager=ContentsManager(), 155s ) 155s 155s notebook/services/sessions/tests/test_sessionmanager.py:45: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:327: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:339: TypeError 155s _______________________________ test_help_output _______________________________ 155s 155s def test_help_output(): 155s """ipython notebook --help-all works""" 155s > check_help_all_output('notebook') 155s 155s notebook/tests/test_notebookapp.py:28: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s pkg = 'notebook', subcommand = None 155s 155s def check_help_all_output(pkg: str, subcommand: Sequence[str] | None = None) -> tuple[str, str]: 155s """test that `python -m PKG --help-all` works""" 155s cmd = [sys.executable, "-m", pkg] 155s if subcommand: 155s cmd.extend(subcommand) 155s cmd.append("--help-all") 155s out, err, rc = get_output_error_code(cmd) 155s > assert rc == 0, err 155s E AssertionError: Traceback (most recent call last): 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s E klass = self._resolve_string(klass) 155s E ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s E return import_item(string) 155s E ^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s E module = __import__(package, fromlist=[obj]) 155s E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s E 155s E During handling of the above exception, another exception occurred: 155s E 155s E Traceback (most recent call last): 155s E File "", line 198, in _run_module_as_main 155s E File "", line 88, in _run_code 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/__main__.py", line 3, in 155s E app.launch_new_instance() 155s E File "/usr/lib/python3/dist-packages/jupyter_core/application.py", line 282, in launch_instance 155s E super().launch_instance(argv=argv, **kwargs) 155s E File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 1073, in launch_instance 155s E app = cls.instance(**kwargs) 155s E ^^^^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/config/configurable.py", line 583, in instance 155s E inst = cls(*args, **kwargs) 155s E ^^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s E inst.setup_instance(*args, **kwargs) 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s E super(HasTraits, self).setup_instance(*args, **kwargs) 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s E init(self) 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s E self._resolve_classes() 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s E warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s /usr/lib/python3/dist-packages/traitlets/tests/utils.py:38: AssertionError 155s ____________________________ test_server_info_file _____________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_server_info_file(): 155s td = TemporaryDirectory() 155s > nbapp = NotebookApp(runtime_dir=td.name, log=logging.getLogger()) 155s 155s notebook/tests/test_notebookapp.py:32: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _________________________________ test_nb_dir __________________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_nb_dir(): 155s with TemporaryDirectory() as td: 155s > app = NotebookApp(notebook_dir=td) 155s 155s notebook/tests/test_notebookapp.py:49: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s ____________________________ test_no_create_nb_dir _____________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_no_create_nb_dir(): 155s with TemporaryDirectory() as td: 155s nbdir = os.path.join(td, 'notebooks') 155s > app = NotebookApp() 155s 155s notebook/tests/test_notebookapp.py:55: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _____________________________ test_missing_nb_dir ______________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_missing_nb_dir(): 155s with TemporaryDirectory() as td: 155s nbdir = os.path.join(td, 'notebook', 'dir', 'is', 'missing') 155s > app = NotebookApp() 155s 155s notebook/tests/test_notebookapp.py:62: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _____________________________ test_invalid_nb_dir ______________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_invalid_nb_dir(): 155s with NamedTemporaryFile() as tf: 155s > app = NotebookApp() 155s 155s notebook/tests/test_notebookapp.py:68: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s ____________________________ test_nb_dir_with_slash ____________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_nb_dir_with_slash(): 155s with TemporaryDirectory(suffix="_slash" + os.sep) as td: 155s > app = NotebookApp(notebook_dir=td) 155s 155s notebook/tests/test_notebookapp.py:74: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _______________________________ test_nb_dir_root _______________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_nb_dir_root(): 155s root = os.path.abspath(os.sep) # gets the right value on Windows, Posix 155s > app = NotebookApp(notebook_dir=root) 155s 155s notebook/tests/test_notebookapp.py:79: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _____________________________ test_generate_config _____________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_generate_config(): 155s with TemporaryDirectory() as td: 155s > app = NotebookApp(config_dir=td) 155s 155s notebook/tests/test_notebookapp.py:84: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s ____________________________ test_notebook_password ____________________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s def test_notebook_password(): 155s password = 'secret' 155s with TemporaryDirectory() as td: 155s with patch.dict('os.environ', { 155s 'JUPYTER_CONFIG_DIR': td, 155s }), patch.object(getpass, 'getpass', return_value=password): 155s app = notebookapp.NotebookPasswordApp(log_level=logging.ERROR) 155s app.initialize([]) 155s app.start() 155s > nb = NotebookApp() 155s 155s notebook/tests/test_notebookapp.py:133: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _________________ TestInstallServerExtension.test_merge_config _________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def test_merge_config(self): 155s # enabled at sys level 155s mock_sys = self._inject_mock_extension('mockext_sys') 155s # enabled at sys, disabled at user 155s mock_both = self._inject_mock_extension('mockext_both') 155s # enabled at user 155s mock_user = self._inject_mock_extension('mockext_user') 155s # enabled at Python 155s mock_py = self._inject_mock_extension('mockext_py') 155s 155s toggle_serverextension_python('mockext_sys', enabled=True, user=False) 155s toggle_serverextension_python('mockext_user', enabled=True, user=True) 155s toggle_serverextension_python('mockext_both', enabled=True, user=False) 155s toggle_serverextension_python('mockext_both', enabled=False, user=True) 155s 155s > app = NotebookApp(nbserver_extensions={'mockext_py': True}) 155s 155s notebook/tests/test_serverextensions.py:147: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _________________ TestOrderedServerExtension.test_load_ordered _________________ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s > klass = self._resolve_string(klass) 155s 155s notebook/traittypes.py:235: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:2015: in _resolve_string 155s return import_item(string) 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s name = 'jupyter_server.contents.services.managers.ContentsManager' 155s 155s def import_item(name: str) -> Any: 155s """Import and return ``bar`` given the string ``foo.bar``. 155s 155s Calling ``bar = import_item("foo.bar")`` is the functional equivalent of 155s executing the code ``from foo import bar``. 155s 155s Parameters 155s ---------- 155s name : string 155s The fully qualified name of the module/package being imported. 155s 155s Returns 155s ------- 155s mod : module object 155s The module that was imported. 155s """ 155s if not isinstance(name, str): 155s raise TypeError("import_item accepts strings, not '%s'." % type(name)) 155s parts = name.rsplit(".", 1) 155s if len(parts) == 2: 155s # called with 'foo.bar....' 155s package, obj = parts 155s > module = __import__(package, fromlist=[obj]) 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s 155s /usr/lib/python3/dist-packages/traitlets/utils/importstring.py:33: ModuleNotFoundError 155s 155s During handling of the above exception, another exception occurred: 155s 155s self = 155s 155s def test_load_ordered(self): 155s > app = NotebookApp() 155s 155s notebook/tests/test_serverextensions.py:189: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1292: in __new__ 155s inst.setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1335: in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s /usr/lib/python3/dist-packages/traitlets/traitlets.py:1311: in setup_instance 155s init(self) 155s notebook/traittypes.py:226: in instance_init 155s self._resolve_classes() 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s self = 155s 155s def _resolve_classes(self): 155s # Resolve all string names to actual classes. 155s self.importable_klasses = [] 155s for klass in self.klasses: 155s if isinstance(klass, str): 155s try: 155s klass = self._resolve_string(klass) 155s self.importable_klasses.append(klass) 155s except: 155s > warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s notebook/traittypes.py:238: TypeError 155s _______________________________ test_help_output _______________________________ 155s 155s def test_help_output(): 155s """jupyter notebook --help-all works""" 155s # FIXME: will be notebook 155s > check_help_all_output('notebook') 155s 155s notebook/tests/test_utils.py:21: 155s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 155s 155s pkg = 'notebook', subcommand = None 155s 155s def check_help_all_output(pkg: str, subcommand: Sequence[str] | None = None) -> tuple[str, str]: 155s """test that `python -m PKG --help-all` works""" 155s cmd = [sys.executable, "-m", pkg] 155s if subcommand: 155s cmd.extend(subcommand) 155s cmd.append("--help-all") 155s out, err, rc = get_output_error_code(cmd) 155s > assert rc == 0, err 155s E AssertionError: Traceback (most recent call last): 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s E klass = self._resolve_string(klass) 155s E ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s E return import_item(string) 155s E ^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s E module = __import__(package, fromlist=[obj]) 155s E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s E ModuleNotFoundError: No module named 'jupyter_server' 155s E 155s E During handling of the above exception, another exception occurred: 155s E 155s E Traceback (most recent call last): 155s E File "", line 198, in _run_module_as_main 155s E File "", line 88, in _run_code 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/__main__.py", line 3, in 155s E app.launch_new_instance() 155s E File "/usr/lib/python3/dist-packages/jupyter_core/application.py", line 282, in launch_instance 155s E super().launch_instance(argv=argv, **kwargs) 155s E File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 1073, in launch_instance 155s E app = cls.instance(**kwargs) 155s E ^^^^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/config/configurable.py", line 583, in instance 155s E inst = cls(*args, **kwargs) 155s E ^^^^^^^^^^^^^^^^^^^^ 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s E inst.setup_instance(*args, **kwargs) 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s E super(HasTraits, self).setup_instance(*args, **kwargs) 155s E File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s E init(self) 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s E self._resolve_classes() 155s E File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s E warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s E TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s /usr/lib/python3/dist-packages/traitlets/tests/utils.py:38: AssertionError 155s =============================== warnings summary =============================== 155s notebook/nbextensions.py:15 155s /tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/nbextensions.py:15: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs 155s given by the platformdirs library. To remove this warning and 155s see the appropriate new directories, set the environment variable 155s `JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`. 155s The use of platformdirs will be the default in `jupyter_core` v6 155s from jupyter_core.paths import ( 155s 155s notebook/utils.py:280 155s notebook/utils.py:280 155s /tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/utils.py:280: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. 155s return LooseVersion(v) >= LooseVersion(check) 155s 155s notebook/_tz.py:29: 1 warning 155s notebook/services/sessions/tests/test_sessionmanager.py: 9 warnings 155s /tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/_tz.py:29: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). 155s dt = unaware(*args, **kwargs) 155s 155s notebook/tests/test_notebookapp_integration.py:14 155s /tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/test_notebookapp_integration.py:14: PytestUnknownMarkWarning: Unknown pytest.mark.integration_tests - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html 155s pytestmark = pytest.mark.integration_tests 155s 155s notebook/auth/tests/test_login.py::LoginTest::test_next_bad 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-1 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/bundler/tests/test_bundler_api.py::BundleAPITest::test_bundler_import_error 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-2 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/api/tests/test_api.py::APITest::test_get_spec 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-3 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/config/tests/test_config_api.py::APITest::test_create_retrieve_config 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-4 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/contents/tests/test_contents_api.py::APITest::test_checkpoints 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-5 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_checkpoints 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-6 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/contents/tests/test_largefilemanager.py: 42 warnings 155s notebook/services/contents/tests/test_manager.py: 526 warnings 155s /tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/_tz.py:29: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC). 155s dt = unaware(*args, **kwargs) 155s 155s notebook/services/kernels/tests/test_kernels_api.py::KernelAPITest::test_connections 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-7 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/kernels/tests/test_kernels_api.py::AsyncKernelAPITest::test_connections 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-8 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/kernels/tests/test_kernels_api.py::KernelFilterTest::test_config 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-9 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/kernels/tests/test_kernels_api.py::KernelCullingTest::test_culling 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-10 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_get_kernel_resource_file 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-11 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/nbconvert/tests/test_nbconvert_api.py::APITest::test_list_formats 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-12 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_create 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-13 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_create 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-14 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_create_terminal 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-15 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/terminal/tests/test_terminals_api.py::TerminalCullingTest::test_config 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-16 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tests/test_files.py::FilesTest::test_contents_manager 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-17 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tests/test_gateway.py::TestGateway::test_gateway_class_mappings 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-18 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tests/test_nbextensions.py::TestInstallNBExtension::test_install_tar 155s notebook/tests/test_nbextensions.py::TestInstallNBExtension::test_install_tar 155s notebook/tests/test_nbextensions.py::TestInstallNBExtension::test_install_tar 155s /tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/nbextensions.py:154: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior. 155s archive.extractall(nbext) 155s 155s notebook/tests/test_notebookapp.py::NotebookAppTests::test_list_running_servers 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-19 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tests/test_notebookapp.py::NotebookUnixSocketTests::test_list_running_sock_servers 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-20 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tests/test_notebookapp.py::NotebookAppJSONLoggingTests::test_log_json_enabled 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-21 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tests/test_paths.py::RedirectTestCase::test_trailing_slash 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-22 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s notebook/tree/tests/test_tree_handler.py::TreeTest::test_redirect 155s /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-23 (start_thread) 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 235, in _resolve_classes 155s klass = self._resolve_string(klass) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 2015, in _resolve_string 155s return import_item(string) 155s ^^^^^^^^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/utils/importstring.py", line 33, in import_item 155s module = __import__(package, fromlist=[obj]) 155s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 155s ModuleNotFoundError: No module named 'jupyter_server' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 155, in start_thread 155s app = cls.notebook = NotebookApp( 155s ^^^^^^^^^^^^ 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1292, in __new__ 155s inst.setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1335, in setup_instance 155s super(HasTraits, self).setup_instance(*args, **kwargs) 155s File "/usr/lib/python3/dist-packages/traitlets/traitlets.py", line 1311, in setup_instance 155s init(self) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 226, in instance_init 155s self._resolve_classes() 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/traittypes.py", line 238, in _resolve_classes 155s warn(f"{klass} is not importable. Is it installed?", ImportWarning) 155s TypeError: warn() missing 1 required keyword-only argument: 'stacklevel' 155s 155s During handling of the above exception, another exception occurred: 155s 155s Traceback (most recent call last): 155s File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner 155s self.run() 155s File "/usr/lib/python3.12/threading.py", line 1010, in run 155s self._target(*self._args, **self._kwargs) 155s File "/tmp/autopkgtest.MsnsbA/build.ybd/src/notebook/tests/launchnotebook.py", line 193, in start_thread 155s app.session_manager.close() 155s ^^^ 155s UnboundLocalError: cannot access local variable 'app' where it is not associated with a value 155s 155s warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) 155s 155s -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html 155s =========================== short test summary info ============================ 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_bad_delete_session 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_bad_get_session 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_bad_update_session 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_delete_session 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_get_session 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_get_session_dead_kernel 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_list_sessions 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_list_sessions_dead_kernel 155s FAILED notebook/services/sessions/tests/test_sessionmanager.py::TestSessionManager::test_update_session 155s FAILED notebook/tests/test_notebookapp.py::test_help_output - AssertionError:... 155s FAILED notebook/tests/test_notebookapp.py::test_server_info_file - TypeError:... 155s FAILED notebook/tests/test_notebookapp.py::test_nb_dir - TypeError: warn() mi... 155s FAILED notebook/tests/test_notebookapp.py::test_no_create_nb_dir - TypeError:... 155s FAILED notebook/tests/test_notebookapp.py::test_missing_nb_dir - TypeError: w... 155s FAILED notebook/tests/test_notebookapp.py::test_invalid_nb_dir - TypeError: w... 155s FAILED notebook/tests/test_notebookapp.py::test_nb_dir_with_slash - TypeError... 155s FAILED notebook/tests/test_notebookapp.py::test_nb_dir_root - TypeError: warn... 155s FAILED notebook/tests/test_notebookapp.py::test_generate_config - TypeError: ... 155s FAILED notebook/tests/test_notebookapp.py::test_notebook_password - TypeError... 155s FAILED notebook/tests/test_serverextensions.py::TestInstallServerExtension::test_merge_config 155s FAILED notebook/tests/test_serverextensions.py::TestOrderedServerExtension::test_load_ordered 155s FAILED notebook/tests/test_utils.py::test_help_output - AssertionError: Trace... 155s ERROR notebook/auth/tests/test_login.py::LoginTest::test_next_bad - RuntimeEr... 155s ERROR notebook/auth/tests/test_login.py::LoginTest::test_next_ok - RuntimeErr... 155s ERROR notebook/bundler/tests/test_bundler_api.py::BundleAPITest::test_bundler_import_error 155s ERROR notebook/bundler/tests/test_bundler_api.py::BundleAPITest::test_bundler_invoke 155s ERROR notebook/bundler/tests/test_bundler_api.py::BundleAPITest::test_bundler_not_enabled 155s ERROR notebook/bundler/tests/test_bundler_api.py::BundleAPITest::test_missing_bundler_arg 155s ERROR notebook/bundler/tests/test_bundler_api.py::BundleAPITest::test_notebook_not_found 155s ERROR notebook/services/api/tests/test_api.py::APITest::test_get_spec - Runti... 155s ERROR notebook/services/api/tests/test_api.py::APITest::test_get_status - Run... 155s ERROR notebook/services/api/tests/test_api.py::APITest::test_no_track_activity 155s ERROR notebook/services/config/tests/test_config_api.py::APITest::test_create_retrieve_config 155s ERROR notebook/services/config/tests/test_config_api.py::APITest::test_get_unknown 155s ERROR notebook/services/config/tests/test_config_api.py::APITest::test_modify 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_checkpoints 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_checkpoints_separate_root 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy_400_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy_copy 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy_dir_400 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy_path 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy_put_400 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_copy_put_400_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_create_untitled 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_create_untitled_txt 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_delete_hidden_dir 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_delete_hidden_file 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_file_checkpoints 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_404_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_bad_type 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_binary_file_contents 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_contents_no_such_file 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_dir_no_content 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_nb_contents 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_nb_invalid 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_nb_no_content 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_get_text_file_contents 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_list_dirs 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_list_nonexistant_dir 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_list_notebooks 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_mkdir 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_mkdir_hidden_400 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_mkdir_untitled 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_rename 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_rename_400_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_rename_existing 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_save 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_upload 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_upload_b64 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_upload_txt 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_upload_txt_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::APITest::test_upload_v2 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_checkpoints 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_checkpoints_separate_root 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_config_did_something 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy_400_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy_copy 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy_dir_400 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy_path 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy_put_400 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_copy_put_400_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_create_untitled 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_create_untitled_txt 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_delete_hidden_dir 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_delete_hidden_file 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_file_checkpoints 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_404_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_bad_type 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_binary_file_contents 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_contents_no_such_file 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_dir_no_content 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_nb_contents 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_nb_invalid 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_nb_no_content 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_get_text_file_contents 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_list_dirs 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_list_nonexistant_dir 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_list_notebooks 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_mkdir 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_mkdir_hidden_400 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_mkdir_untitled 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_rename 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_rename_400_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_rename_existing 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_save 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_upload 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_upload_b64 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_upload_txt 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_upload_txt_hidden 155s ERROR notebook/services/contents/tests/test_contents_api.py::GenericFileCheckpointsAPITest::test_upload_v2 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelAPITest::test_connections 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelAPITest::test_default_kernel 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelAPITest::test_kernel_handler 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelAPITest::test_main_kernel_handler 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelAPITest::test_no_kernels 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::AsyncKernelAPITest::test_connections 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::AsyncKernelAPITest::test_default_kernel 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::AsyncKernelAPITest::test_kernel_handler 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::AsyncKernelAPITest::test_main_kernel_handler 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::AsyncKernelAPITest::test_no_kernels 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelFilterTest::test_config 155s ERROR notebook/services/kernels/tests/test_kernels_api.py::KernelCullingTest::test_culling 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_get_kernel_resource_file 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_get_kernelspec 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_get_kernelspec_spaces 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_get_nonexistant_kernelspec 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_get_nonexistant_resource 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_list_kernelspecs 155s ERROR notebook/services/kernelspecs/tests/test_kernelspecs_api.py::APITest::test_list_kernelspecs_bad 155s ERROR notebook/services/nbconvert/tests/test_nbconvert_api.py::APITest::test_list_formats 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_create 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_create_console_session 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_create_deprecated 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_create_file_session 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_create_with_kernel_id 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_delete 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_modify_kernel_id 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_modify_kernel_name 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_modify_path 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_modify_path_deprecated 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::SessionAPITest::test_modify_type 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_create 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_create_console_session 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_create_deprecated 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_create_file_session 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_create_with_kernel_id 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_delete 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_modify_kernel_id 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_modify_kernel_name 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_modify_path 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_modify_path_deprecated 155s ERROR notebook/services/sessions/tests/test_sessions_api.py::AsyncSessionAPITest::test_modify_type 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_create_terminal 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_create_terminal_via_get 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_create_terminal_with_name 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_no_terminals 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_terminal_handler 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalAPITest::test_terminal_root_handler 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalCullingTest::test_config 155s ERROR notebook/terminal/tests/test_terminals_api.py::TerminalCullingTest::test_culling 155s ERROR notebook/tests/test_files.py::FilesTest::test_contents_manager - Runtim... 155s ERROR notebook/tests/test_files.py::FilesTest::test_download - RuntimeError: ... 155s ERROR notebook/tests/test_files.py::FilesTest::test_hidden_files - RuntimeErr... 155s ERROR notebook/tests/test_files.py::FilesTest::test_old_files_redirect - Runt... 155s ERROR notebook/tests/test_files.py::FilesTest::test_view_html - RuntimeError:... 155s ERROR notebook/tests/test_gateway.py::TestGateway::test_gateway_class_mappings 155s ERROR notebook/tests/test_gateway.py::TestGateway::test_gateway_get_kernelspecs 155s ERROR notebook/tests/test_gateway.py::TestGateway::test_gateway_get_named_kernelspec 155s ERROR notebook/tests/test_gateway.py::TestGateway::test_gateway_kernel_lifecycle 155s ERROR notebook/tests/test_gateway.py::TestGateway::test_gateway_options - Run... 155s ERROR notebook/tests/test_gateway.py::TestGateway::test_gateway_session_lifecycle 155s ERROR notebook/tests/test_notebookapp.py::NotebookAppTests::test_list_running_servers 155s ERROR notebook/tests/test_notebookapp.py::NotebookAppTests::test_log_json_default 155s ERROR notebook/tests/test_notebookapp.py::NotebookAppTests::test_validate_log_json 155s ERROR notebook/tests/test_notebookapp.py::NotebookUnixSocketTests::test_list_running_sock_servers 155s ERROR notebook/tests/test_notebookapp.py::NotebookUnixSocketTests::test_run 155s ERROR notebook/tests/test_notebookapp.py::NotebookAppJSONLoggingTests::test_log_json_enabled 155s ERROR notebook/tests/test_notebookapp.py::NotebookAppJSONLoggingTests::test_validate_log_json 155s ERROR notebook/tests/test_paths.py::RedirectTestCase::test_trailing_slash - R... 155s ERROR notebook/tree/tests/test_tree_handler.py::TreeTest::test_redirect - Run... 155s = 22 failed, 123 passed, 20 skipped, 5 deselected, 608 warnings, 160 errors in 36.70s = 156s autopkgtest [11:39:49]: test pytest: -----------------------] 157s pytest FAIL non-zero exit status 1 157s autopkgtest [11:39:50]: test pytest: - - - - - - - - - - results - - - - - - - - - - 157s autopkgtest [11:39:50]: test command1: preparing testbed 221s autopkgtest [11:40:54]: testbed dpkg architecture: arm64 221s autopkgtest [11:40:54]: testbed apt version: 2.9.5 221s autopkgtest [11:40:54]: @@@@@@@@@@@@@@@@@@@@ test bed setup 222s Get:1 http://ftpmaster.internal/ubuntu oracular-proposed InRelease [110 kB] 222s Get:2 http://ftpmaster.internal/ubuntu oracular-proposed/main Sources [36.1 kB] 222s Get:3 http://ftpmaster.internal/ubuntu oracular-proposed/universe Sources [388 kB] 222s Get:4 http://ftpmaster.internal/ubuntu oracular-proposed/restricted Sources [7052 B] 222s Get:5 http://ftpmaster.internal/ubuntu oracular-proposed/multiverse Sources [2576 B] 222s Get:6 http://ftpmaster.internal/ubuntu oracular-proposed/main arm64 Packages [55.3 kB] 222s Get:7 http://ftpmaster.internal/ubuntu oracular-proposed/restricted arm64 Packages [33.3 kB] 222s Get:8 http://ftpmaster.internal/ubuntu oracular-proposed/universe arm64 Packages [311 kB] 223s Get:9 http://ftpmaster.internal/ubuntu oracular-proposed/multiverse arm64 Packages [8312 B] 223s Fetched 952 kB in 1s (966 kB/s) 223s Reading package lists... 225s Reading package lists... 225s Building dependency tree... 225s Reading state information... 226s Calculating upgrade... 226s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 226s Reading package lists... 226s Building dependency tree... 226s Reading state information... 227s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 227s Hit:1 http://ftpmaster.internal/ubuntu oracular InRelease 227s Hit:2 http://ftpmaster.internal/ubuntu oracular-updates InRelease 227s Hit:3 http://ftpmaster.internal/ubuntu oracular-security InRelease 227s Hit:4 http://ftpmaster.internal/ubuntu oracular-proposed InRelease 228s Reading package lists... 228s Reading package lists... 229s Building dependency tree... 229s Reading state information... 229s Calculating upgrade... 229s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 230s Reading package lists... 230s Building dependency tree... 230s Reading state information... 230s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 234s Reading package lists... 234s Building dependency tree... 234s Reading state information... 235s Starting pkgProblemResolver with broken count: 0 235s Starting 2 pkgProblemResolver with broken count: 0 235s Done 235s The following additional packages will be installed: 235s fonts-font-awesome fonts-glyphicons-halflings fonts-lato fonts-mathjax gdb 235s jupyter-core jupyter-notebook libbabeltrace1 libdebuginfod-common 235s libdebuginfod1t64 libjs-backbone libjs-bootstrap libjs-bootstrap-tour 235s libjs-codemirror libjs-es6-promise libjs-jed libjs-jquery 235s libjs-jquery-typeahead libjs-jquery-ui libjs-marked libjs-mathjax 235s libjs-moment libjs-requirejs libjs-requirejs-text libjs-sphinxdoc 235s libjs-text-encoding libjs-underscore libjs-xterm libnorm1t64 libpgm-5.3-0t64 235s libpython3.12t64 libsodium23 libsource-highlight-common 235s libsource-highlight4t64 libzmq5 node-jed python-notebook-doc 235s python-tinycss2-common python3-argon2 python3-asttokens python3-bleach 235s python3-bs4 python3-bytecode python3-comm python3-coverage python3-dateutil 235s python3-debugpy python3-decorator python3-defusedxml python3-entrypoints 235s python3-executing python3-fastjsonschema python3-html5lib python3-ipykernel 235s python3-ipython python3-ipython-genutils python3-jedi python3-jupyter-client 235s python3-jupyter-core python3-jupyterlab-pygments python3-matplotlib-inline 235s python3-mistune python3-nbclient python3-nbconvert python3-nbformat 235s python3-nest-asyncio python3-notebook python3-packaging 235s python3-pandocfilters python3-parso python3-pexpect python3-platformdirs 235s python3-prometheus-client python3-prompt-toolkit python3-psutil 235s python3-ptyprocess python3-pure-eval python3-py python3-pydevd 235s python3-send2trash python3-setuptools python3-soupsieve python3-stack-data 235s python3-terminado python3-tinycss2 python3-tornado python3-traitlets 235s python3-typeshed python3-wcwidth python3-webencodings python3-zmq 235s sphinx-rtd-theme-common 235s Suggested packages: 235s gdb-doc gdbserver libjs-jquery-lazyload libjs-json libjs-jquery-ui-docs 235s fonts-mathjax-extras fonts-stix libjs-mathjax-doc python-argon2-doc 235s python-bleach-doc python-bytecode-doc python-coverage-doc 235s python-fastjsonschema-doc python3-genshi python3-lxml python-ipython-doc 235s python3-pip python-nbconvert-doc texlive-fonts-recommended 235s texlive-plain-generic texlive-xetex python-pexpect-doc subversion 235s python3-pytest pydevd python-setuptools-doc python-terminado-doc 235s python-tinycss2-doc python3-pycurl python-tornado-doc python3-twisted 235s Recommended packages: 235s libc-dbg javascript-common python3-lxml python3-matplotlib pandoc 235s python3-ipywidgets 235s The following NEW packages will be installed: 235s autopkgtest-satdep fonts-font-awesome fonts-glyphicons-halflings fonts-lato 235s fonts-mathjax gdb jupyter-core jupyter-notebook libbabeltrace1 235s libdebuginfod-common libdebuginfod1t64 libjs-backbone libjs-bootstrap 235s libjs-bootstrap-tour libjs-codemirror libjs-es6-promise libjs-jed 235s libjs-jquery libjs-jquery-typeahead libjs-jquery-ui libjs-marked 235s libjs-mathjax libjs-moment libjs-requirejs libjs-requirejs-text 235s libjs-sphinxdoc libjs-text-encoding libjs-underscore libjs-xterm libnorm1t64 235s libpgm-5.3-0t64 libpython3.12t64 libsodium23 libsource-highlight-common 235s libsource-highlight4t64 libzmq5 node-jed python-notebook-doc 235s python-tinycss2-common python3-argon2 python3-asttokens python3-bleach 235s python3-bs4 python3-bytecode python3-comm python3-coverage python3-dateutil 235s python3-debugpy python3-decorator python3-defusedxml python3-entrypoints 235s python3-executing python3-fastjsonschema python3-html5lib python3-ipykernel 235s python3-ipython python3-ipython-genutils python3-jedi python3-jupyter-client 235s python3-jupyter-core python3-jupyterlab-pygments python3-matplotlib-inline 235s python3-mistune python3-nbclient python3-nbconvert python3-nbformat 235s python3-nest-asyncio python3-notebook python3-packaging 235s python3-pandocfilters python3-parso python3-pexpect python3-platformdirs 235s python3-prometheus-client python3-prompt-toolkit python3-psutil 235s python3-ptyprocess python3-pure-eval python3-py python3-pydevd 235s python3-send2trash python3-setuptools python3-soupsieve python3-stack-data 235s python3-terminado python3-tinycss2 python3-tornado python3-traitlets 235s python3-typeshed python3-wcwidth python3-webencodings python3-zmq 235s sphinx-rtd-theme-common 235s 0 upgraded, 93 newly installed, 0 to remove and 0 not upgraded. 235s Need to get 34.1 MB/34.1 MB of archives. 235s After this operation, 176 MB of additional disk space will be used. 235s Get:1 /tmp/autopkgtest.MsnsbA/2-autopkgtest-satdep.deb autopkgtest-satdep arm64 0 [728 B] 235s Get:2 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-lato all 2.015-1 [2781 kB] 236s Get:3 http://ftpmaster.internal/ubuntu oracular/main arm64 libdebuginfod-common all 0.191-1 [14.6 kB] 236s Get:4 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-font-awesome all 5.0.10+really4.7.0~dfsg-4.1 [516 kB] 236s Get:5 http://ftpmaster.internal/ubuntu oracular/universe arm64 fonts-glyphicons-halflings all 1.009~3.4.1+dfsg-3 [118 kB] 236s Get:6 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-mathjax all 2.7.9+dfsg-1 [2208 kB] 236s Get:7 http://ftpmaster.internal/ubuntu oracular/main arm64 libbabeltrace1 arm64 1.5.11-3build3 [159 kB] 236s Get:8 http://ftpmaster.internal/ubuntu oracular/main arm64 libdebuginfod1t64 arm64 0.191-1 [16.2 kB] 236s Get:9 http://ftpmaster.internal/ubuntu oracular/main arm64 libpython3.12t64 arm64 3.12.4-1 [2280 kB] 236s Get:10 http://ftpmaster.internal/ubuntu oracular/main arm64 libsource-highlight-common all 3.1.9-4.3build1 [64.2 kB] 236s Get:11 http://ftpmaster.internal/ubuntu oracular/main arm64 libsource-highlight4t64 arm64 3.1.9-4.3build1 [243 kB] 236s Get:12 http://ftpmaster.internal/ubuntu oracular/main arm64 gdb arm64 15.0.50.20240403-0ubuntu1 [4837 kB] 236s Get:13 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-platformdirs all 4.2.1-1 [16.3 kB] 236s Get:14 http://ftpmaster.internal/ubuntu oracular-proposed/universe arm64 python3-traitlets all 5.14.3-1 [71.3 kB] 236s Get:15 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyter-core all 5.3.2-2 [25.5 kB] 236s Get:16 http://ftpmaster.internal/ubuntu oracular/universe arm64 jupyter-core all 5.3.2-2 [4038 B] 236s Get:17 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-underscore all 1.13.4~dfsg+~1.11.4-3 [118 kB] 236s Get:18 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-backbone all 1.4.1~dfsg+~1.4.15-3 [185 kB] 236s Get:19 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-bootstrap all 3.4.1+dfsg-3 [129 kB] 236s Get:20 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-jquery all 3.6.1+dfsg+~3.5.14-1 [328 kB] 236s Get:21 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-bootstrap-tour all 0.12.0+dfsg-5 [21.4 kB] 236s Get:22 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-codemirror all 5.65.0+~cs5.83.9-3 [755 kB] 236s Get:23 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-es6-promise all 4.2.8-12 [14.1 kB] 236s Get:24 http://ftpmaster.internal/ubuntu oracular/universe arm64 node-jed all 1.1.1-4 [15.2 kB] 236s Get:25 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jed all 1.1.1-4 [2584 B] 236s Get:26 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jquery-typeahead all 2.11.0+dfsg1-3 [48.9 kB] 236s Get:27 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jquery-ui all 1.13.2+dfsg-1 [252 kB] 236s Get:28 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-marked all 4.2.3+ds+~4.0.7-3 [36.2 kB] 236s Get:29 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-mathjax all 2.7.9+dfsg-1 [5665 kB] 237s Get:30 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-moment all 2.29.4+ds-1 [147 kB] 237s Get:31 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-requirejs all 2.3.6+ds+~2.1.37-1 [201 kB] 237s Get:32 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-requirejs-text all 2.0.12-1.1 [9056 B] 237s Get:33 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-text-encoding all 0.7.0-5 [140 kB] 237s Get:34 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-xterm all 5.3.0-2 [476 kB] 237s Get:35 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-ptyprocess all 0.7.0-5 [15.1 kB] 237s Get:36 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-tornado arm64 6.4.1-1 [298 kB] 237s Get:37 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-terminado all 0.18.1-1 [13.2 kB] 237s Get:38 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-argon2 arm64 21.1.0-2build1 [21.4 kB] 237s Get:39 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-comm all 0.2.1-1 [7016 B] 237s Get:40 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-bytecode all 0.15.1-3 [44.7 kB] 237s Get:41 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-coverage arm64 7.4.4+dfsg1-0ubuntu2 [148 kB] 237s Get:42 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pydevd arm64 2.10.0+ds-10ubuntu1 [600 kB] 237s Get:43 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-debugpy all 1.8.0+ds-4ubuntu4 [67.6 kB] 237s Get:44 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-decorator all 5.1.1-5 [10.1 kB] 237s Get:45 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-parso all 0.8.3-1 [67.2 kB] 237s Get:46 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-typeshed all 0.0~git20231111.6764465-3 [1274 kB] 237s Get:47 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jedi all 0.19.1+ds1-1 [693 kB] 237s Get:48 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-matplotlib-inline all 0.1.6-2 [8784 B] 237s Get:49 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-pexpect all 4.9-2 [48.1 kB] 237s Get:50 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-wcwidth all 0.2.5+dfsg1-1.1ubuntu1 [22.5 kB] 237s Get:51 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-prompt-toolkit all 3.0.46-1 [256 kB] 237s Get:52 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-asttokens all 2.4.1-1 [20.9 kB] 237s Get:53 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-executing all 2.0.1-0.1 [23.3 kB] 237s Get:54 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pure-eval all 0.2.2-2 [11.1 kB] 237s Get:55 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-stack-data all 0.6.3-1 [22.0 kB] 237s Get:56 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-setuptools all 68.1.2-2ubuntu1 [396 kB] 237s Get:57 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipython all 8.20.0-1ubuntu1 [561 kB] 237s Get:58 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-dateutil all 2.9.0-2 [80.3 kB] 237s Get:59 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-entrypoints all 0.4-2 [7146 B] 237s Get:60 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nest-asyncio all 1.5.4-1 [6256 B] 237s Get:61 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-py all 1.11.0-2 [72.7 kB] 237s Get:62 http://ftpmaster.internal/ubuntu oracular/universe arm64 libnorm1t64 arm64 1.5.9+dfsg-3.1build1 [150 kB] 237s Get:63 http://ftpmaster.internal/ubuntu oracular/universe arm64 libpgm-5.3-0t64 arm64 5.3.128~dfsg-2.1build1 [162 kB] 237s Get:64 http://ftpmaster.internal/ubuntu oracular/main arm64 libsodium23 arm64 1.0.18-1build3 [119 kB] 237s Get:65 http://ftpmaster.internal/ubuntu oracular/universe arm64 libzmq5 arm64 4.3.5-1build2 [247 kB] 237s Get:66 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-zmq arm64 24.0.1-5build1 [280 kB] 237s Get:67 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyter-client all 7.4.9-2ubuntu1 [90.5 kB] 237s Get:68 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-packaging all 24.0-1 [41.1 kB] 237s Get:69 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-psutil arm64 5.9.8-2build2 [196 kB] 237s Get:70 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipykernel all 6.29.3-1ubuntu1 [82.6 kB] 237s Get:71 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipython-genutils all 0.2.0-6 [22.0 kB] 237s Get:72 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-webencodings all 0.5.1-5 [11.5 kB] 237s Get:73 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-html5lib all 1.1-6 [88.8 kB] 237s Get:74 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-bleach all 6.1.0-2 [49.6 kB] 237s Get:75 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-soupsieve all 2.5-1 [33.0 kB] 237s Get:76 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-bs4 all 4.12.3-1 [109 kB] 237s Get:77 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-defusedxml all 0.7.1-2 [42.0 kB] 237s Get:78 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyterlab-pygments all 0.2.2-3 [6054 B] 237s Get:79 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-mistune all 3.0.2-1 [32.8 kB] 237s Get:80 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-fastjsonschema all 2.19.1-1 [19.7 kB] 237s Get:81 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbformat all 5.9.1-1 [41.2 kB] 237s Get:82 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbclient all 0.8.0-1 [55.6 kB] 237s Get:83 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pandocfilters all 1.5.1-1 [23.6 kB] 237s Get:84 http://ftpmaster.internal/ubuntu oracular/universe arm64 python-tinycss2-common all 1.3.0-1 [34.1 kB] 237s Get:85 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-tinycss2 all 1.3.0-1 [19.6 kB] 237s Get:86 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbconvert all 7.16.4-1 [156 kB] 237s Get:87 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-prometheus-client all 0.19.0+ds1-1 [41.7 kB] 237s Get:88 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-send2trash all 1.8.2-1 [15.5 kB] 237s Get:89 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-notebook all 6.4.12-2.2ubuntu1 [1566 kB] 237s Get:90 http://ftpmaster.internal/ubuntu oracular/universe arm64 jupyter-notebook all 6.4.12-2.2ubuntu1 [10.4 kB] 237s Get:91 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-sphinxdoc all 7.2.6-8 [150 kB] 237s Get:92 http://ftpmaster.internal/ubuntu oracular/main arm64 sphinx-rtd-theme-common all 2.0.0+dfsg-1 [1012 kB] 237s Get:93 http://ftpmaster.internal/ubuntu oracular/universe arm64 python-notebook-doc all 6.4.12-2.2ubuntu1 [2540 kB] 238s Preconfiguring packages ... 238s Fetched 34.1 MB in 2s (14.9 MB/s) 238s Selecting previously unselected package fonts-lato. 239s (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 78264 files and directories currently installed.) 239s Preparing to unpack .../00-fonts-lato_2.015-1_all.deb ... 239s Unpacking fonts-lato (2.015-1) ... 239s Selecting previously unselected package libdebuginfod-common. 239s Preparing to unpack .../01-libdebuginfod-common_0.191-1_all.deb ... 239s Unpacking libdebuginfod-common (0.191-1) ... 239s Selecting previously unselected package fonts-font-awesome. 239s Preparing to unpack .../02-fonts-font-awesome_5.0.10+really4.7.0~dfsg-4.1_all.deb ... 239s Unpacking fonts-font-awesome (5.0.10+really4.7.0~dfsg-4.1) ... 239s Selecting previously unselected package fonts-glyphicons-halflings. 239s Preparing to unpack .../03-fonts-glyphicons-halflings_1.009~3.4.1+dfsg-3_all.deb ... 239s Unpacking fonts-glyphicons-halflings (1.009~3.4.1+dfsg-3) ... 239s Selecting previously unselected package fonts-mathjax. 239s Preparing to unpack .../04-fonts-mathjax_2.7.9+dfsg-1_all.deb ... 239s Unpacking fonts-mathjax (2.7.9+dfsg-1) ... 239s Selecting previously unselected package libbabeltrace1:arm64. 239s Preparing to unpack .../05-libbabeltrace1_1.5.11-3build3_arm64.deb ... 239s Unpacking libbabeltrace1:arm64 (1.5.11-3build3) ... 239s Selecting previously unselected package libdebuginfod1t64:arm64. 239s Preparing to unpack .../06-libdebuginfod1t64_0.191-1_arm64.deb ... 239s Unpacking libdebuginfod1t64:arm64 (0.191-1) ... 239s Selecting previously unselected package libpython3.12t64:arm64. 239s Preparing to unpack .../07-libpython3.12t64_3.12.4-1_arm64.deb ... 239s Unpacking libpython3.12t64:arm64 (3.12.4-1) ... 239s Selecting previously unselected package libsource-highlight-common. 239s Preparing to unpack .../08-libsource-highlight-common_3.1.9-4.3build1_all.deb ... 239s Unpacking libsource-highlight-common (3.1.9-4.3build1) ... 239s Selecting previously unselected package libsource-highlight4t64:arm64. 239s Preparing to unpack .../09-libsource-highlight4t64_3.1.9-4.3build1_arm64.deb ... 239s Unpacking libsource-highlight4t64:arm64 (3.1.9-4.3build1) ... 239s Selecting previously unselected package gdb. 239s Preparing to unpack .../10-gdb_15.0.50.20240403-0ubuntu1_arm64.deb ... 239s Unpacking gdb (15.0.50.20240403-0ubuntu1) ... 240s Selecting previously unselected package python3-platformdirs. 240s Preparing to unpack .../11-python3-platformdirs_4.2.1-1_all.deb ... 240s Unpacking python3-platformdirs (4.2.1-1) ... 240s Selecting previously unselected package python3-traitlets. 240s Preparing to unpack .../12-python3-traitlets_5.14.3-1_all.deb ... 240s Unpacking python3-traitlets (5.14.3-1) ... 240s Selecting previously unselected package python3-jupyter-core. 240s Preparing to unpack .../13-python3-jupyter-core_5.3.2-2_all.deb ... 240s Unpacking python3-jupyter-core (5.3.2-2) ... 240s Selecting previously unselected package jupyter-core. 240s Preparing to unpack .../14-jupyter-core_5.3.2-2_all.deb ... 240s Unpacking jupyter-core (5.3.2-2) ... 240s Selecting previously unselected package libjs-underscore. 240s Preparing to unpack .../15-libjs-underscore_1.13.4~dfsg+~1.11.4-3_all.deb ... 240s Unpacking libjs-underscore (1.13.4~dfsg+~1.11.4-3) ... 240s Selecting previously unselected package libjs-backbone. 240s Preparing to unpack .../16-libjs-backbone_1.4.1~dfsg+~1.4.15-3_all.deb ... 240s Unpacking libjs-backbone (1.4.1~dfsg+~1.4.15-3) ... 240s Selecting previously unselected package libjs-bootstrap. 240s Preparing to unpack .../17-libjs-bootstrap_3.4.1+dfsg-3_all.deb ... 240s Unpacking libjs-bootstrap (3.4.1+dfsg-3) ... 240s Selecting previously unselected package libjs-jquery. 240s Preparing to unpack .../18-libjs-jquery_3.6.1+dfsg+~3.5.14-1_all.deb ... 240s Unpacking libjs-jquery (3.6.1+dfsg+~3.5.14-1) ... 240s Selecting previously unselected package libjs-bootstrap-tour. 240s Preparing to unpack .../19-libjs-bootstrap-tour_0.12.0+dfsg-5_all.deb ... 240s Unpacking libjs-bootstrap-tour (0.12.0+dfsg-5) ... 240s Selecting previously unselected package libjs-codemirror. 240s Preparing to unpack .../20-libjs-codemirror_5.65.0+~cs5.83.9-3_all.deb ... 240s Unpacking libjs-codemirror (5.65.0+~cs5.83.9-3) ... 240s Selecting previously unselected package libjs-es6-promise. 240s Preparing to unpack .../21-libjs-es6-promise_4.2.8-12_all.deb ... 240s Unpacking libjs-es6-promise (4.2.8-12) ... 240s Selecting previously unselected package node-jed. 240s Preparing to unpack .../22-node-jed_1.1.1-4_all.deb ... 240s Unpacking node-jed (1.1.1-4) ... 240s Selecting previously unselected package libjs-jed. 240s Preparing to unpack .../23-libjs-jed_1.1.1-4_all.deb ... 240s Unpacking libjs-jed (1.1.1-4) ... 240s Selecting previously unselected package libjs-jquery-typeahead. 240s Preparing to unpack .../24-libjs-jquery-typeahead_2.11.0+dfsg1-3_all.deb ... 240s Unpacking libjs-jquery-typeahead (2.11.0+dfsg1-3) ... 240s Selecting previously unselected package libjs-jquery-ui. 240s Preparing to unpack .../25-libjs-jquery-ui_1.13.2+dfsg-1_all.deb ... 240s Unpacking libjs-jquery-ui (1.13.2+dfsg-1) ... 240s Selecting previously unselected package libjs-marked. 240s Preparing to unpack .../26-libjs-marked_4.2.3+ds+~4.0.7-3_all.deb ... 240s Unpacking libjs-marked (4.2.3+ds+~4.0.7-3) ... 240s Selecting previously unselected package libjs-mathjax. 240s Preparing to unpack .../27-libjs-mathjax_2.7.9+dfsg-1_all.deb ... 240s Unpacking libjs-mathjax (2.7.9+dfsg-1) ... 241s Selecting previously unselected package libjs-moment. 241s Preparing to unpack .../28-libjs-moment_2.29.4+ds-1_all.deb ... 241s Unpacking libjs-moment (2.29.4+ds-1) ... 241s Selecting previously unselected package libjs-requirejs. 241s Preparing to unpack .../29-libjs-requirejs_2.3.6+ds+~2.1.37-1_all.deb ... 241s Unpacking libjs-requirejs (2.3.6+ds+~2.1.37-1) ... 241s Selecting previously unselected package libjs-requirejs-text. 241s Preparing to unpack .../30-libjs-requirejs-text_2.0.12-1.1_all.deb ... 241s Unpacking libjs-requirejs-text (2.0.12-1.1) ... 241s Selecting previously unselected package libjs-text-encoding. 241s Preparing to unpack .../31-libjs-text-encoding_0.7.0-5_all.deb ... 241s Unpacking libjs-text-encoding (0.7.0-5) ... 241s Selecting previously unselected package libjs-xterm. 241s Preparing to unpack .../32-libjs-xterm_5.3.0-2_all.deb ... 241s Unpacking libjs-xterm (5.3.0-2) ... 241s Selecting previously unselected package python3-ptyprocess. 241s Preparing to unpack .../33-python3-ptyprocess_0.7.0-5_all.deb ... 241s Unpacking python3-ptyprocess (0.7.0-5) ... 241s Selecting previously unselected package python3-tornado. 241s Preparing to unpack .../34-python3-tornado_6.4.1-1_arm64.deb ... 241s Unpacking python3-tornado (6.4.1-1) ... 241s Selecting previously unselected package python3-terminado. 241s Preparing to unpack .../35-python3-terminado_0.18.1-1_all.deb ... 241s Unpacking python3-terminado (0.18.1-1) ... 241s Selecting previously unselected package python3-argon2. 241s Preparing to unpack .../36-python3-argon2_21.1.0-2build1_arm64.deb ... 241s Unpacking python3-argon2 (21.1.0-2build1) ... 241s Selecting previously unselected package python3-comm. 241s Preparing to unpack .../37-python3-comm_0.2.1-1_all.deb ... 241s Unpacking python3-comm (0.2.1-1) ... 241s Selecting previously unselected package python3-bytecode. 241s Preparing to unpack .../38-python3-bytecode_0.15.1-3_all.deb ... 241s Unpacking python3-bytecode (0.15.1-3) ... 241s Selecting previously unselected package python3-coverage. 241s Preparing to unpack .../39-python3-coverage_7.4.4+dfsg1-0ubuntu2_arm64.deb ... 241s Unpacking python3-coverage (7.4.4+dfsg1-0ubuntu2) ... 241s Selecting previously unselected package python3-pydevd. 241s Preparing to unpack .../40-python3-pydevd_2.10.0+ds-10ubuntu1_arm64.deb ... 241s Unpacking python3-pydevd (2.10.0+ds-10ubuntu1) ... 241s Selecting previously unselected package python3-debugpy. 241s Preparing to unpack .../41-python3-debugpy_1.8.0+ds-4ubuntu4_all.deb ... 241s Unpacking python3-debugpy (1.8.0+ds-4ubuntu4) ... 241s Selecting previously unselected package python3-decorator. 241s Preparing to unpack .../42-python3-decorator_5.1.1-5_all.deb ... 241s Unpacking python3-decorator (5.1.1-5) ... 241s Selecting previously unselected package python3-parso. 241s Preparing to unpack .../43-python3-parso_0.8.3-1_all.deb ... 241s Unpacking python3-parso (0.8.3-1) ... 241s Selecting previously unselected package python3-typeshed. 241s Preparing to unpack .../44-python3-typeshed_0.0~git20231111.6764465-3_all.deb ... 241s Unpacking python3-typeshed (0.0~git20231111.6764465-3) ... 242s Selecting previously unselected package python3-jedi. 242s Preparing to unpack .../45-python3-jedi_0.19.1+ds1-1_all.deb ... 242s Unpacking python3-jedi (0.19.1+ds1-1) ... 242s Selecting previously unselected package python3-matplotlib-inline. 242s Preparing to unpack .../46-python3-matplotlib-inline_0.1.6-2_all.deb ... 242s Unpacking python3-matplotlib-inline (0.1.6-2) ... 242s Selecting previously unselected package python3-pexpect. 242s Preparing to unpack .../47-python3-pexpect_4.9-2_all.deb ... 242s Unpacking python3-pexpect (4.9-2) ... 242s Selecting previously unselected package python3-wcwidth. 242s Preparing to unpack .../48-python3-wcwidth_0.2.5+dfsg1-1.1ubuntu1_all.deb ... 242s Unpacking python3-wcwidth (0.2.5+dfsg1-1.1ubuntu1) ... 242s Selecting previously unselected package python3-prompt-toolkit. 242s Preparing to unpack .../49-python3-prompt-toolkit_3.0.46-1_all.deb ... 242s Unpacking python3-prompt-toolkit (3.0.46-1) ... 242s Selecting previously unselected package python3-asttokens. 242s Preparing to unpack .../50-python3-asttokens_2.4.1-1_all.deb ... 242s Unpacking python3-asttokens (2.4.1-1) ... 242s Selecting previously unselected package python3-executing. 242s Preparing to unpack .../51-python3-executing_2.0.1-0.1_all.deb ... 242s Unpacking python3-executing (2.0.1-0.1) ... 242s Selecting previously unselected package python3-pure-eval. 242s Preparing to unpack .../52-python3-pure-eval_0.2.2-2_all.deb ... 242s Unpacking python3-pure-eval (0.2.2-2) ... 242s Selecting previously unselected package python3-stack-data. 242s Preparing to unpack .../53-python3-stack-data_0.6.3-1_all.deb ... 242s Unpacking python3-stack-data (0.6.3-1) ... 242s Selecting previously unselected package python3-setuptools. 242s Preparing to unpack .../54-python3-setuptools_68.1.2-2ubuntu1_all.deb ... 242s Unpacking python3-setuptools (68.1.2-2ubuntu1) ... 242s Selecting previously unselected package python3-ipython. 242s Preparing to unpack .../55-python3-ipython_8.20.0-1ubuntu1_all.deb ... 242s Unpacking python3-ipython (8.20.0-1ubuntu1) ... 243s Selecting previously unselected package python3-dateutil. 243s Preparing to unpack .../56-python3-dateutil_2.9.0-2_all.deb ... 243s Unpacking python3-dateutil (2.9.0-2) ... 243s Selecting previously unselected package python3-entrypoints. 243s Preparing to unpack .../57-python3-entrypoints_0.4-2_all.deb ... 243s Unpacking python3-entrypoints (0.4-2) ... 243s Selecting previously unselected package python3-nest-asyncio. 243s Preparing to unpack .../58-python3-nest-asyncio_1.5.4-1_all.deb ... 243s Unpacking python3-nest-asyncio (1.5.4-1) ... 243s Selecting previously unselected package python3-py. 243s Preparing to unpack .../59-python3-py_1.11.0-2_all.deb ... 243s Unpacking python3-py (1.11.0-2) ... 243s Selecting previously unselected package libnorm1t64:arm64. 243s Preparing to unpack .../60-libnorm1t64_1.5.9+dfsg-3.1build1_arm64.deb ... 243s Unpacking libnorm1t64:arm64 (1.5.9+dfsg-3.1build1) ... 243s Selecting previously unselected package libpgm-5.3-0t64:arm64. 243s Preparing to unpack .../61-libpgm-5.3-0t64_5.3.128~dfsg-2.1build1_arm64.deb ... 243s Unpacking libpgm-5.3-0t64:arm64 (5.3.128~dfsg-2.1build1) ... 243s Selecting previously unselected package libsodium23:arm64. 243s Preparing to unpack .../62-libsodium23_1.0.18-1build3_arm64.deb ... 243s Unpacking libsodium23:arm64 (1.0.18-1build3) ... 243s Selecting previously unselected package libzmq5:arm64. 243s Preparing to unpack .../63-libzmq5_4.3.5-1build2_arm64.deb ... 243s Unpacking libzmq5:arm64 (4.3.5-1build2) ... 243s Selecting previously unselected package python3-zmq. 243s Preparing to unpack .../64-python3-zmq_24.0.1-5build1_arm64.deb ... 243s Unpacking python3-zmq (24.0.1-5build1) ... 243s Selecting previously unselected package python3-jupyter-client. 243s Preparing to unpack .../65-python3-jupyter-client_7.4.9-2ubuntu1_all.deb ... 243s Unpacking python3-jupyter-client (7.4.9-2ubuntu1) ... 243s Selecting previously unselected package python3-packaging. 243s Preparing to unpack .../66-python3-packaging_24.0-1_all.deb ... 243s Unpacking python3-packaging (24.0-1) ... 243s Selecting previously unselected package python3-psutil. 243s Preparing to unpack .../67-python3-psutil_5.9.8-2build2_arm64.deb ... 243s Unpacking python3-psutil (5.9.8-2build2) ... 243s Selecting previously unselected package python3-ipykernel. 243s Preparing to unpack .../68-python3-ipykernel_6.29.3-1ubuntu1_all.deb ... 243s Unpacking python3-ipykernel (6.29.3-1ubuntu1) ... 243s Selecting previously unselected package python3-ipython-genutils. 243s Preparing to unpack .../69-python3-ipython-genutils_0.2.0-6_all.deb ... 243s Unpacking python3-ipython-genutils (0.2.0-6) ... 243s Selecting previously unselected package python3-webencodings. 243s Preparing to unpack .../70-python3-webencodings_0.5.1-5_all.deb ... 243s Unpacking python3-webencodings (0.5.1-5) ... 243s Selecting previously unselected package python3-html5lib. 243s Preparing to unpack .../71-python3-html5lib_1.1-6_all.deb ... 243s Unpacking python3-html5lib (1.1-6) ... 243s Selecting previously unselected package python3-bleach. 243s Preparing to unpack .../72-python3-bleach_6.1.0-2_all.deb ... 243s Unpacking python3-bleach (6.1.0-2) ... 243s Selecting previously unselected package python3-soupsieve. 243s Preparing to unpack .../73-python3-soupsieve_2.5-1_all.deb ... 243s Unpacking python3-soupsieve (2.5-1) ... 243s Selecting previously unselected package python3-bs4. 243s Preparing to unpack .../74-python3-bs4_4.12.3-1_all.deb ... 243s Unpacking python3-bs4 (4.12.3-1) ... 243s Selecting previously unselected package python3-defusedxml. 243s Preparing to unpack .../75-python3-defusedxml_0.7.1-2_all.deb ... 243s Unpacking python3-defusedxml (0.7.1-2) ... 243s Selecting previously unselected package python3-jupyterlab-pygments. 243s Preparing to unpack .../76-python3-jupyterlab-pygments_0.2.2-3_all.deb ... 243s Unpacking python3-jupyterlab-pygments (0.2.2-3) ... 243s Selecting previously unselected package python3-mistune. 243s Preparing to unpack .../77-python3-mistune_3.0.2-1_all.deb ... 243s Unpacking python3-mistune (3.0.2-1) ... 243s Selecting previously unselected package python3-fastjsonschema. 243s Preparing to unpack .../78-python3-fastjsonschema_2.19.1-1_all.deb ... 243s Unpacking python3-fastjsonschema (2.19.1-1) ... 243s Selecting previously unselected package python3-nbformat. 243s Preparing to unpack .../79-python3-nbformat_5.9.1-1_all.deb ... 243s Unpacking python3-nbformat (5.9.1-1) ... 243s Selecting previously unselected package python3-nbclient. 243s Preparing to unpack .../80-python3-nbclient_0.8.0-1_all.deb ... 243s Unpacking python3-nbclient (0.8.0-1) ... 243s Selecting previously unselected package python3-pandocfilters. 243s Preparing to unpack .../81-python3-pandocfilters_1.5.1-1_all.deb ... 243s Unpacking python3-pandocfilters (1.5.1-1) ... 243s Selecting previously unselected package python-tinycss2-common. 243s Preparing to unpack .../82-python-tinycss2-common_1.3.0-1_all.deb ... 243s Unpacking python-tinycss2-common (1.3.0-1) ... 243s Selecting previously unselected package python3-tinycss2. 244s Preparing to unpack .../83-python3-tinycss2_1.3.0-1_all.deb ... 244s Unpacking python3-tinycss2 (1.3.0-1) ... 244s Selecting previously unselected package python3-nbconvert. 244s Preparing to unpack .../84-python3-nbconvert_7.16.4-1_all.deb ... 244s Unpacking python3-nbconvert (7.16.4-1) ... 244s Selecting previously unselected package python3-prometheus-client. 244s Preparing to unpack .../85-python3-prometheus-client_0.19.0+ds1-1_all.deb ... 244s Unpacking python3-prometheus-client (0.19.0+ds1-1) ... 244s Selecting previously unselected package python3-send2trash. 244s Preparing to unpack .../86-python3-send2trash_1.8.2-1_all.deb ... 244s Unpacking python3-send2trash (1.8.2-1) ... 244s Selecting previously unselected package python3-notebook. 244s Preparing to unpack .../87-python3-notebook_6.4.12-2.2ubuntu1_all.deb ... 244s Unpacking python3-notebook (6.4.12-2.2ubuntu1) ... 244s Selecting previously unselected package jupyter-notebook. 244s Preparing to unpack .../88-jupyter-notebook_6.4.12-2.2ubuntu1_all.deb ... 244s Unpacking jupyter-notebook (6.4.12-2.2ubuntu1) ... 244s Selecting previously unselected package libjs-sphinxdoc. 244s Preparing to unpack .../89-libjs-sphinxdoc_7.2.6-8_all.deb ... 244s Unpacking libjs-sphinxdoc (7.2.6-8) ... 244s Selecting previously unselected package sphinx-rtd-theme-common. 244s Preparing to unpack .../90-sphinx-rtd-theme-common_2.0.0+dfsg-1_all.deb ... 244s Unpacking sphinx-rtd-theme-common (2.0.0+dfsg-1) ... 244s Selecting previously unselected package python-notebook-doc. 244s Preparing to unpack .../91-python-notebook-doc_6.4.12-2.2ubuntu1_all.deb ... 244s Unpacking python-notebook-doc (6.4.12-2.2ubuntu1) ... 244s Selecting previously unselected package autopkgtest-satdep. 244s Preparing to unpack .../92-2-autopkgtest-satdep.deb ... 244s Unpacking autopkgtest-satdep (0) ... 244s Setting up python3-entrypoints (0.4-2) ... 244s Setting up libjs-jquery-typeahead (2.11.0+dfsg1-3) ... 244s Setting up python3-tornado (6.4.1-1) ... 245s Setting up libnorm1t64:arm64 (1.5.9+dfsg-3.1build1) ... 245s Setting up python3-pure-eval (0.2.2-2) ... 245s Setting up python3-send2trash (1.8.2-1) ... 245s Setting up fonts-lato (2.015-1) ... 245s Setting up fonts-mathjax (2.7.9+dfsg-1) ... 245s Setting up libsodium23:arm64 (1.0.18-1build3) ... 245s Setting up python3-setuptools (68.1.2-2ubuntu1) ... 245s Setting up libjs-mathjax (2.7.9+dfsg-1) ... 245s Setting up python3-py (1.11.0-2) ... 245s Setting up libdebuginfod-common (0.191-1) ... 246s Setting up libjs-requirejs-text (2.0.12-1.1) ... 246s Setting up python3-parso (0.8.3-1) ... 246s Setting up python3-defusedxml (0.7.1-2) ... 246s Setting up python3-ipython-genutils (0.2.0-6) ... 246s Setting up python3-asttokens (2.4.1-1) ... 246s Setting up fonts-glyphicons-halflings (1.009~3.4.1+dfsg-3) ... 246s Setting up python3-coverage (7.4.4+dfsg1-0ubuntu2) ... 246s Setting up libjs-moment (2.29.4+ds-1) ... 246s Setting up python3-pandocfilters (1.5.1-1) ... 246s Setting up libjs-requirejs (2.3.6+ds+~2.1.37-1) ... 246s Setting up libjs-es6-promise (4.2.8-12) ... 246s Setting up libjs-text-encoding (0.7.0-5) ... 246s Setting up python3-webencodings (0.5.1-5) ... 246s Setting up python3-platformdirs (4.2.1-1) ... 247s Setting up python3-psutil (5.9.8-2build2) ... 247s Setting up libsource-highlight-common (3.1.9-4.3build1) ... 247s Setting up python3-jupyterlab-pygments (0.2.2-3) ... 247s Setting up libpython3.12t64:arm64 (3.12.4-1) ... 247s Setting up libpgm-5.3-0t64:arm64 (5.3.128~dfsg-2.1build1) ... 247s Setting up python3-decorator (5.1.1-5) ... 247s Setting up python3-packaging (24.0-1) ... 247s Setting up python3-wcwidth (0.2.5+dfsg1-1.1ubuntu1) ... 247s Setting up node-jed (1.1.1-4) ... 247s Setting up python3-typeshed (0.0~git20231111.6764465-3) ... 247s Setting up python3-executing (2.0.1-0.1) ... 248s Setting up libjs-xterm (5.3.0-2) ... 248s Setting up python3-nest-asyncio (1.5.4-1) ... 248s Setting up python3-bytecode (0.15.1-3) ... 248s Setting up libjs-codemirror (5.65.0+~cs5.83.9-3) ... 248s Setting up libjs-jed (1.1.1-4) ... 248s Setting up python3-html5lib (1.1-6) ... 248s Setting up libbabeltrace1:arm64 (1.5.11-3build3) ... 248s Setting up python3-fastjsonschema (2.19.1-1) ... 248s Setting up python3-traitlets (5.14.3-1) ... 248s Setting up python-tinycss2-common (1.3.0-1) ... 248s Setting up python3-argon2 (21.1.0-2build1) ... 248s Setting up python3-dateutil (2.9.0-2) ... 249s Setting up libjs-jquery (3.6.1+dfsg+~3.5.14-1) ... 249s Setting up python3-mistune (3.0.2-1) ... 249s Setting up python3-stack-data (0.6.3-1) ... 249s Setting up python3-soupsieve (2.5-1) ... 249s Setting up fonts-font-awesome (5.0.10+really4.7.0~dfsg-4.1) ... 249s Setting up sphinx-rtd-theme-common (2.0.0+dfsg-1) ... 249s Setting up python3-jupyter-core (5.3.2-2) ... 249s Setting up libjs-bootstrap (3.4.1+dfsg-3) ... 249s Setting up libjs-underscore (1.13.4~dfsg+~1.11.4-3) ... 249s Setting up python3-ptyprocess (0.7.0-5) ... 249s Setting up libjs-marked (4.2.3+ds+~4.0.7-3) ... 249s Setting up python3-prompt-toolkit (3.0.46-1) ... 250s Setting up libdebuginfod1t64:arm64 (0.191-1) ... 250s Setting up python3-tinycss2 (1.3.0-1) ... 250s Setting up libzmq5:arm64 (4.3.5-1build2) ... 250s Setting up python3-jedi (0.19.1+ds1-1) ... 250s Setting up libjs-bootstrap-tour (0.12.0+dfsg-5) ... 250s Setting up libjs-backbone (1.4.1~dfsg+~1.4.15-3) ... 250s Setting up libsource-highlight4t64:arm64 (3.1.9-4.3build1) ... 250s Setting up python3-nbformat (5.9.1-1) ... 250s Setting up python3-bs4 (4.12.3-1) ... 250s Setting up python3-bleach (6.1.0-2) ... 251s Setting up python3-matplotlib-inline (0.1.6-2) ... 251s Setting up python3-comm (0.2.1-1) ... 251s Setting up python3-prometheus-client (0.19.0+ds1-1) ... 251s Setting up gdb (15.0.50.20240403-0ubuntu1) ... 251s Setting up libjs-jquery-ui (1.13.2+dfsg-1) ... 251s Setting up python3-pexpect (4.9-2) ... 251s Setting up python3-zmq (24.0.1-5build1) ... 252s Setting up libjs-sphinxdoc (7.2.6-8) ... 252s Setting up python3-terminado (0.18.1-1) ... 252s Setting up python3-jupyter-client (7.4.9-2ubuntu1) ... 252s Setting up jupyter-core (5.3.2-2) ... 252s Setting up python3-pydevd (2.10.0+ds-10ubuntu1) ... 252s Setting up python3-debugpy (1.8.0+ds-4ubuntu4) ... 253s Setting up python-notebook-doc (6.4.12-2.2ubuntu1) ... 253s Setting up python3-nbclient (0.8.0-1) ... 253s Setting up python3-ipython (8.20.0-1ubuntu1) ... 253s Setting up python3-ipykernel (6.29.3-1ubuntu1) ... 254s Setting up python3-nbconvert (7.16.4-1) ... 254s Setting up python3-notebook (6.4.12-2.2ubuntu1) ... 254s Setting up jupyter-notebook (6.4.12-2.2ubuntu1) ... 254s Setting up autopkgtest-satdep (0) ... 254s Processing triggers for man-db (2.12.1-2) ... 255s Processing triggers for libc-bin (2.39-0ubuntu9) ... 261s (Reading database ... 94935 files and directories currently installed.) 261s Removing autopkgtest-satdep (0) ... 263s autopkgtest [11:41:36]: test command1: find /usr/lib/python3/dist-packages/notebook -xtype l >&2 263s autopkgtest [11:41:36]: test command1: [----------------------- 263s autopkgtest [11:41:36]: test command1: -----------------------] 264s command1 PASS (superficial) 264s autopkgtest [11:41:37]: test command1: - - - - - - - - - - results - - - - - - - - - - 264s autopkgtest [11:41:37]: test autodep8-python3: preparing testbed 328s autopkgtest [11:42:41]: testbed dpkg architecture: arm64 328s autopkgtest [11:42:41]: testbed apt version: 2.9.5 328s autopkgtest [11:42:41]: @@@@@@@@@@@@@@@@@@@@ test bed setup 328s Get:1 http://ftpmaster.internal/ubuntu oracular-proposed InRelease [110 kB] 328s Get:2 http://ftpmaster.internal/ubuntu oracular-proposed/main Sources [36.1 kB] 329s Get:3 http://ftpmaster.internal/ubuntu oracular-proposed/multiverse Sources [2576 B] 329s Get:4 http://ftpmaster.internal/ubuntu oracular-proposed/universe Sources [388 kB] 329s Get:5 http://ftpmaster.internal/ubuntu oracular-proposed/restricted Sources [7052 B] 329s Get:6 http://ftpmaster.internal/ubuntu oracular-proposed/main arm64 Packages [55.3 kB] 329s Get:7 http://ftpmaster.internal/ubuntu oracular-proposed/restricted arm64 Packages [33.3 kB] 329s Get:8 http://ftpmaster.internal/ubuntu oracular-proposed/universe arm64 Packages [311 kB] 329s Get:9 http://ftpmaster.internal/ubuntu oracular-proposed/multiverse arm64 Packages [8312 B] 329s Fetched 952 kB in 1s (1072 kB/s) 329s Reading package lists... 331s Reading package lists... 331s Building dependency tree... 331s Reading state information... 332s Calculating upgrade... 332s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 332s Reading package lists... 332s Building dependency tree... 332s Reading state information... 333s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 334s Hit:1 http://ftpmaster.internal/ubuntu oracular InRelease 334s Hit:2 http://ftpmaster.internal/ubuntu oracular-updates InRelease 334s Hit:3 http://ftpmaster.internal/ubuntu oracular-security InRelease 334s Hit:4 http://ftpmaster.internal/ubuntu oracular-proposed InRelease 335s Reading package lists... 335s Reading package lists... 335s Building dependency tree... 335s Reading state information... 336s Calculating upgrade... 336s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 336s Reading package lists... 336s Building dependency tree... 336s Reading state information... 337s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 340s Reading package lists... 341s Building dependency tree... 341s Reading state information... 341s Starting pkgProblemResolver with broken count: 0 341s Starting 2 pkgProblemResolver with broken count: 0 341s Done 342s The following additional packages will be installed: 342s fonts-font-awesome fonts-glyphicons-halflings fonts-mathjax gdb 342s libbabeltrace1 libdebuginfod-common libdebuginfod1t64 libjs-backbone 342s libjs-bootstrap libjs-bootstrap-tour libjs-codemirror libjs-es6-promise 342s libjs-jed libjs-jquery libjs-jquery-typeahead libjs-jquery-ui libjs-marked 342s libjs-mathjax libjs-moment libjs-requirejs libjs-requirejs-text 342s libjs-text-encoding libjs-underscore libjs-xterm libnorm1t64 libpgm-5.3-0t64 342s libpython3.12t64 libsodium23 libsource-highlight-common 342s libsource-highlight4t64 libzmq5 node-jed python-tinycss2-common python3-all 342s python3-argon2 python3-asttokens python3-bleach python3-bs4 python3-bytecode 342s python3-comm python3-coverage python3-dateutil python3-debugpy 342s python3-decorator python3-defusedxml python3-entrypoints python3-executing 342s python3-fastjsonschema python3-html5lib python3-ipykernel python3-ipython 342s python3-ipython-genutils python3-jedi python3-jupyter-client 342s python3-jupyter-core python3-jupyterlab-pygments python3-matplotlib-inline 342s python3-mistune python3-nbclient python3-nbconvert python3-nbformat 342s python3-nest-asyncio python3-notebook python3-packaging 342s python3-pandocfilters python3-parso python3-pexpect python3-platformdirs 342s python3-prometheus-client python3-prompt-toolkit python3-psutil 342s python3-ptyprocess python3-pure-eval python3-py python3-pydevd 342s python3-send2trash python3-setuptools python3-soupsieve python3-stack-data 342s python3-terminado python3-tinycss2 python3-tornado python3-traitlets 342s python3-typeshed python3-wcwidth python3-webencodings python3-zmq 342s Suggested packages: 342s gdb-doc gdbserver libjs-jquery-lazyload libjs-json libjs-jquery-ui-docs 342s fonts-mathjax-extras fonts-stix libjs-mathjax-doc python-argon2-doc 342s python-bleach-doc python-bytecode-doc python-coverage-doc 342s python-fastjsonschema-doc python3-genshi python3-lxml python-ipython-doc 342s python3-pip python-nbconvert-doc texlive-fonts-recommended 342s texlive-plain-generic texlive-xetex python-notebook-doc python-pexpect-doc 342s subversion python3-pytest pydevd python-setuptools-doc python-terminado-doc 342s python-tinycss2-doc python3-pycurl python-tornado-doc python3-twisted 342s Recommended packages: 342s libc-dbg javascript-common python3-lxml python3-matplotlib pandoc 342s python3-ipywidgets 342s The following NEW packages will be installed: 342s autopkgtest-satdep fonts-font-awesome fonts-glyphicons-halflings 342s fonts-mathjax gdb libbabeltrace1 libdebuginfod-common libdebuginfod1t64 342s libjs-backbone libjs-bootstrap libjs-bootstrap-tour libjs-codemirror 342s libjs-es6-promise libjs-jed libjs-jquery libjs-jquery-typeahead 342s libjs-jquery-ui libjs-marked libjs-mathjax libjs-moment libjs-requirejs 342s libjs-requirejs-text libjs-text-encoding libjs-underscore libjs-xterm 342s libnorm1t64 libpgm-5.3-0t64 libpython3.12t64 libsodium23 342s libsource-highlight-common libsource-highlight4t64 libzmq5 node-jed 342s python-tinycss2-common python3-all python3-argon2 python3-asttokens 342s python3-bleach python3-bs4 python3-bytecode python3-comm python3-coverage 342s python3-dateutil python3-debugpy python3-decorator python3-defusedxml 342s python3-entrypoints python3-executing python3-fastjsonschema 342s python3-html5lib python3-ipykernel python3-ipython python3-ipython-genutils 342s python3-jedi python3-jupyter-client python3-jupyter-core 342s python3-jupyterlab-pygments python3-matplotlib-inline python3-mistune 342s python3-nbclient python3-nbconvert python3-nbformat python3-nest-asyncio 342s python3-notebook python3-packaging python3-pandocfilters python3-parso 342s python3-pexpect python3-platformdirs python3-prometheus-client 342s python3-prompt-toolkit python3-psutil python3-ptyprocess python3-pure-eval 342s python3-py python3-pydevd python3-send2trash python3-setuptools 342s python3-soupsieve python3-stack-data python3-terminado python3-tinycss2 342s python3-tornado python3-traitlets python3-typeshed python3-wcwidth 342s python3-webencodings python3-zmq 342s 0 upgraded, 88 newly installed, 0 to remove and 0 not upgraded. 342s Need to get 27.6 MB/27.6 MB of archives. 342s After this operation, 157 MB of additional disk space will be used. 342s Get:1 /tmp/autopkgtest.MsnsbA/3-autopkgtest-satdep.deb autopkgtest-satdep arm64 0 [712 B] 342s Get:2 http://ftpmaster.internal/ubuntu oracular/main arm64 libdebuginfod-common all 0.191-1 [14.6 kB] 342s Get:3 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-font-awesome all 5.0.10+really4.7.0~dfsg-4.1 [516 kB] 342s Get:4 http://ftpmaster.internal/ubuntu oracular/universe arm64 fonts-glyphicons-halflings all 1.009~3.4.1+dfsg-3 [118 kB] 342s Get:5 http://ftpmaster.internal/ubuntu oracular/main arm64 fonts-mathjax all 2.7.9+dfsg-1 [2208 kB] 342s Get:6 http://ftpmaster.internal/ubuntu oracular/main arm64 libbabeltrace1 arm64 1.5.11-3build3 [159 kB] 342s Get:7 http://ftpmaster.internal/ubuntu oracular/main arm64 libdebuginfod1t64 arm64 0.191-1 [16.2 kB] 342s Get:8 http://ftpmaster.internal/ubuntu oracular/main arm64 libpython3.12t64 arm64 3.12.4-1 [2280 kB] 343s Get:9 http://ftpmaster.internal/ubuntu oracular/main arm64 libsource-highlight-common all 3.1.9-4.3build1 [64.2 kB] 343s Get:10 http://ftpmaster.internal/ubuntu oracular/main arm64 libsource-highlight4t64 arm64 3.1.9-4.3build1 [243 kB] 343s Get:11 http://ftpmaster.internal/ubuntu oracular/main arm64 gdb arm64 15.0.50.20240403-0ubuntu1 [4837 kB] 343s Get:12 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-underscore all 1.13.4~dfsg+~1.11.4-3 [118 kB] 343s Get:13 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-backbone all 1.4.1~dfsg+~1.4.15-3 [185 kB] 343s Get:14 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-bootstrap all 3.4.1+dfsg-3 [129 kB] 343s Get:15 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-jquery all 3.6.1+dfsg+~3.5.14-1 [328 kB] 343s Get:16 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-bootstrap-tour all 0.12.0+dfsg-5 [21.4 kB] 343s Get:17 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-es6-promise all 4.2.8-12 [14.1 kB] 343s Get:18 http://ftpmaster.internal/ubuntu oracular/universe arm64 node-jed all 1.1.1-4 [15.2 kB] 343s Get:19 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jed all 1.1.1-4 [2584 B] 343s Get:20 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jquery-typeahead all 2.11.0+dfsg1-3 [48.9 kB] 343s Get:21 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-jquery-ui all 1.13.2+dfsg-1 [252 kB] 343s Get:22 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-moment all 2.29.4+ds-1 [147 kB] 343s Get:23 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-text-encoding all 0.7.0-5 [140 kB] 343s Get:24 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-xterm all 5.3.0-2 [476 kB] 343s Get:25 http://ftpmaster.internal/ubuntu oracular/universe arm64 libnorm1t64 arm64 1.5.9+dfsg-3.1build1 [150 kB] 343s Get:26 http://ftpmaster.internal/ubuntu oracular/universe arm64 libpgm-5.3-0t64 arm64 5.3.128~dfsg-2.1build1 [162 kB] 343s Get:27 http://ftpmaster.internal/ubuntu oracular/main arm64 libsodium23 arm64 1.0.18-1build3 [119 kB] 343s Get:28 http://ftpmaster.internal/ubuntu oracular/universe arm64 libzmq5 arm64 4.3.5-1build2 [247 kB] 343s Get:29 http://ftpmaster.internal/ubuntu oracular/universe arm64 python-tinycss2-common all 1.3.0-1 [34.1 kB] 343s Get:30 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-all arm64 3.12.3-0ubuntu1 [888 B] 343s Get:31 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-argon2 arm64 21.1.0-2build1 [21.4 kB] 343s Get:32 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-asttokens all 2.4.1-1 [20.9 kB] 343s Get:33 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-webencodings all 0.5.1-5 [11.5 kB] 343s Get:34 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-html5lib all 1.1-6 [88.8 kB] 343s Get:35 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-bleach all 6.1.0-2 [49.6 kB] 343s Get:36 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-soupsieve all 2.5-1 [33.0 kB] 343s Get:37 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-bs4 all 4.12.3-1 [109 kB] 343s Get:38 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-bytecode all 0.15.1-3 [44.7 kB] 343s Get:39 http://ftpmaster.internal/ubuntu oracular-proposed/universe arm64 python3-traitlets all 5.14.3-1 [71.3 kB] 343s Get:40 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-comm all 0.2.1-1 [7016 B] 343s Get:41 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-coverage arm64 7.4.4+dfsg1-0ubuntu2 [148 kB] 343s Get:42 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-dateutil all 2.9.0-2 [80.3 kB] 343s Get:43 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pydevd arm64 2.10.0+ds-10ubuntu1 [600 kB] 343s Get:44 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-debugpy all 1.8.0+ds-4ubuntu4 [67.6 kB] 343s Get:45 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-decorator all 5.1.1-5 [10.1 kB] 343s Get:46 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-defusedxml all 0.7.1-2 [42.0 kB] 343s Get:47 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-entrypoints all 0.4-2 [7146 B] 343s Get:48 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-executing all 2.0.1-0.1 [23.3 kB] 343s Get:49 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-fastjsonschema all 2.19.1-1 [19.7 kB] 343s Get:50 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-parso all 0.8.3-1 [67.2 kB] 343s Get:51 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-typeshed all 0.0~git20231111.6764465-3 [1274 kB] 343s Get:52 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jedi all 0.19.1+ds1-1 [693 kB] 343s Get:53 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-matplotlib-inline all 0.1.6-2 [8784 B] 343s Get:54 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-ptyprocess all 0.7.0-5 [15.1 kB] 343s Get:55 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-pexpect all 4.9-2 [48.1 kB] 343s Get:56 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-wcwidth all 0.2.5+dfsg1-1.1ubuntu1 [22.5 kB] 343s Get:57 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-prompt-toolkit all 3.0.46-1 [256 kB] 343s Get:58 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pure-eval all 0.2.2-2 [11.1 kB] 343s Get:59 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-stack-data all 0.6.3-1 [22.0 kB] 343s Get:60 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-setuptools all 68.1.2-2ubuntu1 [396 kB] 343s Get:61 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipython all 8.20.0-1ubuntu1 [561 kB] 343s Get:62 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-platformdirs all 4.2.1-1 [16.3 kB] 343s Get:63 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyter-core all 5.3.2-2 [25.5 kB] 343s Get:64 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nest-asyncio all 1.5.4-1 [6256 B] 343s Get:65 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-tornado arm64 6.4.1-1 [298 kB] 343s Get:66 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-py all 1.11.0-2 [72.7 kB] 343s Get:67 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-zmq arm64 24.0.1-5build1 [280 kB] 343s Get:68 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyter-client all 7.4.9-2ubuntu1 [90.5 kB] 343s Get:69 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-packaging all 24.0-1 [41.1 kB] 343s Get:70 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-psutil arm64 5.9.8-2build2 [196 kB] 343s Get:71 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipykernel all 6.29.3-1ubuntu1 [82.6 kB] 343s Get:72 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-ipython-genutils all 0.2.0-6 [22.0 kB] 343s Get:73 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-jupyterlab-pygments all 0.2.2-3 [6054 B] 343s Get:74 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-mistune all 3.0.2-1 [32.8 kB] 343s Get:75 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbformat all 5.9.1-1 [41.2 kB] 343s Get:76 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbclient all 0.8.0-1 [55.6 kB] 343s Get:77 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-pandocfilters all 1.5.1-1 [23.6 kB] 343s Get:78 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-tinycss2 all 1.3.0-1 [19.6 kB] 343s Get:79 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-nbconvert all 7.16.4-1 [156 kB] 343s Get:80 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-codemirror all 5.65.0+~cs5.83.9-3 [755 kB] 343s Get:81 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-marked all 4.2.3+ds+~4.0.7-3 [36.2 kB] 344s Get:82 http://ftpmaster.internal/ubuntu oracular/main arm64 libjs-mathjax all 2.7.9+dfsg-1 [5665 kB] 344s Get:83 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-requirejs all 2.3.6+ds+~2.1.37-1 [201 kB] 344s Get:84 http://ftpmaster.internal/ubuntu oracular/universe arm64 libjs-requirejs-text all 2.0.12-1.1 [9056 B] 344s Get:85 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-terminado all 0.18.1-1 [13.2 kB] 344s Get:86 http://ftpmaster.internal/ubuntu oracular/main arm64 python3-prometheus-client all 0.19.0+ds1-1 [41.7 kB] 344s Get:87 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-send2trash all 1.8.2-1 [15.5 kB] 344s Get:88 http://ftpmaster.internal/ubuntu oracular/universe arm64 python3-notebook all 6.4.12-2.2ubuntu1 [1566 kB] 344s Preconfiguring packages ... 344s Fetched 27.6 MB in 2s (13.2 MB/s) 345s Selecting previously unselected package libdebuginfod-common. 345s (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 78264 files and directories currently installed.) 345s Preparing to unpack .../00-libdebuginfod-common_0.191-1_all.deb ... 345s Unpacking libdebuginfod-common (0.191-1) ... 345s Selecting previously unselected package fonts-font-awesome. 345s Preparing to unpack .../01-fonts-font-awesome_5.0.10+really4.7.0~dfsg-4.1_all.deb ... 345s Unpacking fonts-font-awesome (5.0.10+really4.7.0~dfsg-4.1) ... 345s Selecting previously unselected package fonts-glyphicons-halflings. 345s Preparing to unpack .../02-fonts-glyphicons-halflings_1.009~3.4.1+dfsg-3_all.deb ... 345s Unpacking fonts-glyphicons-halflings (1.009~3.4.1+dfsg-3) ... 345s Selecting previously unselected package fonts-mathjax. 345s Preparing to unpack .../03-fonts-mathjax_2.7.9+dfsg-1_all.deb ... 345s Unpacking fonts-mathjax (2.7.9+dfsg-1) ... 345s Selecting previously unselected package libbabeltrace1:arm64. 345s Preparing to unpack .../04-libbabeltrace1_1.5.11-3build3_arm64.deb ... 345s Unpacking libbabeltrace1:arm64 (1.5.11-3build3) ... 345s Selecting previously unselected package libdebuginfod1t64:arm64. 345s Preparing to unpack .../05-libdebuginfod1t64_0.191-1_arm64.deb ... 345s Unpacking libdebuginfod1t64:arm64 (0.191-1) ... 345s Selecting previously unselected package libpython3.12t64:arm64. 345s Preparing to unpack .../06-libpython3.12t64_3.12.4-1_arm64.deb ... 345s Unpacking libpython3.12t64:arm64 (3.12.4-1) ... 345s Selecting previously unselected package libsource-highlight-common. 345s Preparing to unpack .../07-libsource-highlight-common_3.1.9-4.3build1_all.deb ... 345s Unpacking libsource-highlight-common (3.1.9-4.3build1) ... 345s Selecting previously unselected package libsource-highlight4t64:arm64. 345s Preparing to unpack .../08-libsource-highlight4t64_3.1.9-4.3build1_arm64.deb ... 345s Unpacking libsource-highlight4t64:arm64 (3.1.9-4.3build1) ... 345s Selecting previously unselected package gdb. 345s Preparing to unpack .../09-gdb_15.0.50.20240403-0ubuntu1_arm64.deb ... 345s Unpacking gdb (15.0.50.20240403-0ubuntu1) ... 345s Selecting previously unselected package libjs-underscore. 345s Preparing to unpack .../10-libjs-underscore_1.13.4~dfsg+~1.11.4-3_all.deb ... 345s Unpacking libjs-underscore (1.13.4~dfsg+~1.11.4-3) ... 345s Selecting previously unselected package libjs-backbone. 345s Preparing to unpack .../11-libjs-backbone_1.4.1~dfsg+~1.4.15-3_all.deb ... 345s Unpacking libjs-backbone (1.4.1~dfsg+~1.4.15-3) ... 345s Selecting previously unselected package libjs-bootstrap. 345s Preparing to unpack .../12-libjs-bootstrap_3.4.1+dfsg-3_all.deb ... 345s Unpacking libjs-bootstrap (3.4.1+dfsg-3) ... 346s Selecting previously unselected package libjs-jquery. 346s Preparing to unpack .../13-libjs-jquery_3.6.1+dfsg+~3.5.14-1_all.deb ... 346s Unpacking libjs-jquery (3.6.1+dfsg+~3.5.14-1) ... 346s Selecting previously unselected package libjs-bootstrap-tour. 346s Preparing to unpack .../14-libjs-bootstrap-tour_0.12.0+dfsg-5_all.deb ... 346s Unpacking libjs-bootstrap-tour (0.12.0+dfsg-5) ... 346s Selecting previously unselected package libjs-es6-promise. 346s Preparing to unpack .../15-libjs-es6-promise_4.2.8-12_all.deb ... 346s Unpacking libjs-es6-promise (4.2.8-12) ... 346s Selecting previously unselected package node-jed. 346s Preparing to unpack .../16-node-jed_1.1.1-4_all.deb ... 346s Unpacking node-jed (1.1.1-4) ... 346s Selecting previously unselected package libjs-jed. 346s Preparing to unpack .../17-libjs-jed_1.1.1-4_all.deb ... 346s Unpacking libjs-jed (1.1.1-4) ... 346s Selecting previously unselected package libjs-jquery-typeahead. 346s Preparing to unpack .../18-libjs-jquery-typeahead_2.11.0+dfsg1-3_all.deb ... 346s Unpacking libjs-jquery-typeahead (2.11.0+dfsg1-3) ... 346s Selecting previously unselected package libjs-jquery-ui. 346s Preparing to unpack .../19-libjs-jquery-ui_1.13.2+dfsg-1_all.deb ... 346s Unpacking libjs-jquery-ui (1.13.2+dfsg-1) ... 346s Selecting previously unselected package libjs-moment. 346s Preparing to unpack .../20-libjs-moment_2.29.4+ds-1_all.deb ... 346s Unpacking libjs-moment (2.29.4+ds-1) ... 346s Selecting previously unselected package libjs-text-encoding. 346s Preparing to unpack .../21-libjs-text-encoding_0.7.0-5_all.deb ... 346s Unpacking libjs-text-encoding (0.7.0-5) ... 346s Selecting previously unselected package libjs-xterm. 346s Preparing to unpack .../22-libjs-xterm_5.3.0-2_all.deb ... 346s Unpacking libjs-xterm (5.3.0-2) ... 346s Selecting previously unselected package libnorm1t64:arm64. 346s Preparing to unpack .../23-libnorm1t64_1.5.9+dfsg-3.1build1_arm64.deb ... 346s Unpacking libnorm1t64:arm64 (1.5.9+dfsg-3.1build1) ... 346s Selecting previously unselected package libpgm-5.3-0t64:arm64. 346s Preparing to unpack .../24-libpgm-5.3-0t64_5.3.128~dfsg-2.1build1_arm64.deb ... 346s Unpacking libpgm-5.3-0t64:arm64 (5.3.128~dfsg-2.1build1) ... 346s Selecting previously unselected package libsodium23:arm64. 346s Preparing to unpack .../25-libsodium23_1.0.18-1build3_arm64.deb ... 346s Unpacking libsodium23:arm64 (1.0.18-1build3) ... 346s Selecting previously unselected package libzmq5:arm64. 346s Preparing to unpack .../26-libzmq5_4.3.5-1build2_arm64.deb ... 346s Unpacking libzmq5:arm64 (4.3.5-1build2) ... 346s Selecting previously unselected package python-tinycss2-common. 346s Preparing to unpack .../27-python-tinycss2-common_1.3.0-1_all.deb ... 346s Unpacking python-tinycss2-common (1.3.0-1) ... 346s Selecting previously unselected package python3-all. 346s Preparing to unpack .../28-python3-all_3.12.3-0ubuntu1_arm64.deb ... 346s Unpacking python3-all (3.12.3-0ubuntu1) ... 346s Selecting previously unselected package python3-argon2. 346s Preparing to unpack .../29-python3-argon2_21.1.0-2build1_arm64.deb ... 346s Unpacking python3-argon2 (21.1.0-2build1) ... 346s Selecting previously unselected package python3-asttokens. 346s Preparing to unpack .../30-python3-asttokens_2.4.1-1_all.deb ... 346s Unpacking python3-asttokens (2.4.1-1) ... 346s Selecting previously unselected package python3-webencodings. 346s Preparing to unpack .../31-python3-webencodings_0.5.1-5_all.deb ... 346s Unpacking python3-webencodings (0.5.1-5) ... 346s Selecting previously unselected package python3-html5lib. 346s Preparing to unpack .../32-python3-html5lib_1.1-6_all.deb ... 346s Unpacking python3-html5lib (1.1-6) ... 346s Selecting previously unselected package python3-bleach. 346s Preparing to unpack .../33-python3-bleach_6.1.0-2_all.deb ... 346s Unpacking python3-bleach (6.1.0-2) ... 346s Selecting previously unselected package python3-soupsieve. 346s Preparing to unpack .../34-python3-soupsieve_2.5-1_all.deb ... 346s Unpacking python3-soupsieve (2.5-1) ... 346s Selecting previously unselected package python3-bs4. 346s Preparing to unpack .../35-python3-bs4_4.12.3-1_all.deb ... 346s Unpacking python3-bs4 (4.12.3-1) ... 346s Selecting previously unselected package python3-bytecode. 346s Preparing to unpack .../36-python3-bytecode_0.15.1-3_all.deb ... 346s Unpacking python3-bytecode (0.15.1-3) ... 346s Selecting previously unselected package python3-traitlets. 346s Preparing to unpack .../37-python3-traitlets_5.14.3-1_all.deb ... 346s Unpacking python3-traitlets (5.14.3-1) ... 346s Selecting previously unselected package python3-comm. 346s Preparing to unpack .../38-python3-comm_0.2.1-1_all.deb ... 346s Unpacking python3-comm (0.2.1-1) ... 346s Selecting previously unselected package python3-coverage. 346s Preparing to unpack .../39-python3-coverage_7.4.4+dfsg1-0ubuntu2_arm64.deb ... 346s Unpacking python3-coverage (7.4.4+dfsg1-0ubuntu2) ... 346s Selecting previously unselected package python3-dateutil. 346s Preparing to unpack .../40-python3-dateutil_2.9.0-2_all.deb ... 346s Unpacking python3-dateutil (2.9.0-2) ... 346s Selecting previously unselected package python3-pydevd. 347s Preparing to unpack .../41-python3-pydevd_2.10.0+ds-10ubuntu1_arm64.deb ... 347s Unpacking python3-pydevd (2.10.0+ds-10ubuntu1) ... 347s Selecting previously unselected package python3-debugpy. 347s Preparing to unpack .../42-python3-debugpy_1.8.0+ds-4ubuntu4_all.deb ... 347s Unpacking python3-debugpy (1.8.0+ds-4ubuntu4) ... 347s Selecting previously unselected package python3-decorator. 347s Preparing to unpack .../43-python3-decorator_5.1.1-5_all.deb ... 347s Unpacking python3-decorator (5.1.1-5) ... 347s Selecting previously unselected package python3-defusedxml. 347s Preparing to unpack .../44-python3-defusedxml_0.7.1-2_all.deb ... 347s Unpacking python3-defusedxml (0.7.1-2) ... 347s Selecting previously unselected package python3-entrypoints. 347s Preparing to unpack .../45-python3-entrypoints_0.4-2_all.deb ... 347s Unpacking python3-entrypoints (0.4-2) ... 347s Selecting previously unselected package python3-executing. 347s Preparing to unpack .../46-python3-executing_2.0.1-0.1_all.deb ... 347s Unpacking python3-executing (2.0.1-0.1) ... 347s Selecting previously unselected package python3-fastjsonschema. 347s Preparing to unpack .../47-python3-fastjsonschema_2.19.1-1_all.deb ... 347s Unpacking python3-fastjsonschema (2.19.1-1) ... 347s Selecting previously unselected package python3-parso. 347s Preparing to unpack .../48-python3-parso_0.8.3-1_all.deb ... 347s Unpacking python3-parso (0.8.3-1) ... 347s Selecting previously unselected package python3-typeshed. 347s Preparing to unpack .../49-python3-typeshed_0.0~git20231111.6764465-3_all.deb ... 347s Unpacking python3-typeshed (0.0~git20231111.6764465-3) ... 347s Selecting previously unselected package python3-jedi. 347s Preparing to unpack .../50-python3-jedi_0.19.1+ds1-1_all.deb ... 347s Unpacking python3-jedi (0.19.1+ds1-1) ... 347s Selecting previously unselected package python3-matplotlib-inline. 347s Preparing to unpack .../51-python3-matplotlib-inline_0.1.6-2_all.deb ... 347s Unpacking python3-matplotlib-inline (0.1.6-2) ... 347s Selecting previously unselected package python3-ptyprocess. 348s Preparing to unpack .../52-python3-ptyprocess_0.7.0-5_all.deb ... 348s Unpacking python3-ptyprocess (0.7.0-5) ... 348s Selecting previously unselected package python3-pexpect. 348s Preparing to unpack .../53-python3-pexpect_4.9-2_all.deb ... 348s Unpacking python3-pexpect (4.9-2) ... 348s Selecting previously unselected package python3-wcwidth. 348s Preparing to unpack .../54-python3-wcwidth_0.2.5+dfsg1-1.1ubuntu1_all.deb ... 348s Unpacking python3-wcwidth (0.2.5+dfsg1-1.1ubuntu1) ... 348s Selecting previously unselected package python3-prompt-toolkit. 348s Preparing to unpack .../55-python3-prompt-toolkit_3.0.46-1_all.deb ... 348s Unpacking python3-prompt-toolkit (3.0.46-1) ... 348s Selecting previously unselected package python3-pure-eval. 348s Preparing to unpack .../56-python3-pure-eval_0.2.2-2_all.deb ... 348s Unpacking python3-pure-eval (0.2.2-2) ... 348s Selecting previously unselected package python3-stack-data. 348s Preparing to unpack .../57-python3-stack-data_0.6.3-1_all.deb ... 348s Unpacking python3-stack-data (0.6.3-1) ... 348s Selecting previously unselected package python3-setuptools. 348s Preparing to unpack .../58-python3-setuptools_68.1.2-2ubuntu1_all.deb ... 348s Unpacking python3-setuptools (68.1.2-2ubuntu1) ... 348s Selecting previously unselected package python3-ipython. 348s Preparing to unpack .../59-python3-ipython_8.20.0-1ubuntu1_all.deb ... 348s Unpacking python3-ipython (8.20.0-1ubuntu1) ... 348s Selecting previously unselected package python3-platformdirs. 348s Preparing to unpack .../60-python3-platformdirs_4.2.1-1_all.deb ... 348s Unpacking python3-platformdirs (4.2.1-1) ... 348s Selecting previously unselected package python3-jupyter-core. 348s Preparing to unpack .../61-python3-jupyter-core_5.3.2-2_all.deb ... 348s Unpacking python3-jupyter-core (5.3.2-2) ... 348s Selecting previously unselected package python3-nest-asyncio. 348s Preparing to unpack .../62-python3-nest-asyncio_1.5.4-1_all.deb ... 348s Unpacking python3-nest-asyncio (1.5.4-1) ... 348s Selecting previously unselected package python3-tornado. 348s Preparing to unpack .../63-python3-tornado_6.4.1-1_arm64.deb ... 348s Unpacking python3-tornado (6.4.1-1) ... 348s Selecting previously unselected package python3-py. 348s Preparing to unpack .../64-python3-py_1.11.0-2_all.deb ... 348s Unpacking python3-py (1.11.0-2) ... 348s Selecting previously unselected package python3-zmq. 348s Preparing to unpack .../65-python3-zmq_24.0.1-5build1_arm64.deb ... 348s Unpacking python3-zmq (24.0.1-5build1) ... 348s Selecting previously unselected package python3-jupyter-client. 348s Preparing to unpack .../66-python3-jupyter-client_7.4.9-2ubuntu1_all.deb ... 348s Unpacking python3-jupyter-client (7.4.9-2ubuntu1) ... 348s Selecting previously unselected package python3-packaging. 348s Preparing to unpack .../67-python3-packaging_24.0-1_all.deb ... 348s Unpacking python3-packaging (24.0-1) ... 348s Selecting previously unselected package python3-psutil. 348s Preparing to unpack .../68-python3-psutil_5.9.8-2build2_arm64.deb ... 348s Unpacking python3-psutil (5.9.8-2build2) ... 348s Selecting previously unselected package python3-ipykernel. 348s Preparing to unpack .../69-python3-ipykernel_6.29.3-1ubuntu1_all.deb ... 348s Unpacking python3-ipykernel (6.29.3-1ubuntu1) ... 348s Selecting previously unselected package python3-ipython-genutils. 348s Preparing to unpack .../70-python3-ipython-genutils_0.2.0-6_all.deb ... 348s Unpacking python3-ipython-genutils (0.2.0-6) ... 348s Selecting previously unselected package python3-jupyterlab-pygments. 348s Preparing to unpack .../71-python3-jupyterlab-pygments_0.2.2-3_all.deb ... 348s Unpacking python3-jupyterlab-pygments (0.2.2-3) ... 348s Selecting previously unselected package python3-mistune. 348s Preparing to unpack .../72-python3-mistune_3.0.2-1_all.deb ... 348s Unpacking python3-mistune (3.0.2-1) ... 348s Selecting previously unselected package python3-nbformat. 348s Preparing to unpack .../73-python3-nbformat_5.9.1-1_all.deb ... 348s Unpacking python3-nbformat (5.9.1-1) ... 348s Selecting previously unselected package python3-nbclient. 348s Preparing to unpack .../74-python3-nbclient_0.8.0-1_all.deb ... 348s Unpacking python3-nbclient (0.8.0-1) ... 348s Selecting previously unselected package python3-pandocfilters. 349s Preparing to unpack .../75-python3-pandocfilters_1.5.1-1_all.deb ... 349s Unpacking python3-pandocfilters (1.5.1-1) ... 349s Selecting previously unselected package python3-tinycss2. 349s Preparing to unpack .../76-python3-tinycss2_1.3.0-1_all.deb ... 349s Unpacking python3-tinycss2 (1.3.0-1) ... 349s Selecting previously unselected package python3-nbconvert. 349s Preparing to unpack .../77-python3-nbconvert_7.16.4-1_all.deb ... 349s Unpacking python3-nbconvert (7.16.4-1) ... 349s Selecting previously unselected package libjs-codemirror. 349s Preparing to unpack .../78-libjs-codemirror_5.65.0+~cs5.83.9-3_all.deb ... 349s Unpacking libjs-codemirror (5.65.0+~cs5.83.9-3) ... 349s Selecting previously unselected package libjs-marked. 349s Preparing to unpack .../79-libjs-marked_4.2.3+ds+~4.0.7-3_all.deb ... 349s Unpacking libjs-marked (4.2.3+ds+~4.0.7-3) ... 349s Selecting previously unselected package libjs-mathjax. 349s Preparing to unpack .../80-libjs-mathjax_2.7.9+dfsg-1_all.deb ... 349s Unpacking libjs-mathjax (2.7.9+dfsg-1) ... 349s Selecting previously unselected package libjs-requirejs. 349s Preparing to unpack .../81-libjs-requirejs_2.3.6+ds+~2.1.37-1_all.deb ... 349s Unpacking libjs-requirejs (2.3.6+ds+~2.1.37-1) ... 349s Selecting previously unselected package libjs-requirejs-text. 349s Preparing to unpack .../82-libjs-requirejs-text_2.0.12-1.1_all.deb ... 349s Unpacking libjs-requirejs-text (2.0.12-1.1) ... 349s Selecting previously unselected package python3-terminado. 349s Preparing to unpack .../83-python3-terminado_0.18.1-1_all.deb ... 349s Unpacking python3-terminado (0.18.1-1) ... 349s Selecting previously unselected package python3-prometheus-client. 350s Preparing to unpack .../84-python3-prometheus-client_0.19.0+ds1-1_all.deb ... 350s Unpacking python3-prometheus-client (0.19.0+ds1-1) ... 350s Selecting previously unselected package python3-send2trash. 350s Preparing to unpack .../85-python3-send2trash_1.8.2-1_all.deb ... 350s Unpacking python3-send2trash (1.8.2-1) ... 350s Selecting previously unselected package python3-notebook. 350s Preparing to unpack .../86-python3-notebook_6.4.12-2.2ubuntu1_all.deb ... 350s Unpacking python3-notebook (6.4.12-2.2ubuntu1) ... 350s Selecting previously unselected package autopkgtest-satdep. 350s Preparing to unpack .../87-3-autopkgtest-satdep.deb ... 350s Unpacking autopkgtest-satdep (0) ... 350s Setting up python3-entrypoints (0.4-2) ... 350s Setting up libjs-jquery-typeahead (2.11.0+dfsg1-3) ... 350s Setting up python3-tornado (6.4.1-1) ... 350s Setting up libnorm1t64:arm64 (1.5.9+dfsg-3.1build1) ... 350s Setting up python3-pure-eval (0.2.2-2) ... 351s Setting up python3-send2trash (1.8.2-1) ... 351s Setting up fonts-mathjax (2.7.9+dfsg-1) ... 351s Setting up libsodium23:arm64 (1.0.18-1build3) ... 351s Setting up python3-setuptools (68.1.2-2ubuntu1) ... 351s Setting up libjs-mathjax (2.7.9+dfsg-1) ... 351s Setting up python3-py (1.11.0-2) ... 351s Setting up libdebuginfod-common (0.191-1) ... 351s Setting up libjs-requirejs-text (2.0.12-1.1) ... 351s Setting up python3-parso (0.8.3-1) ... 352s Setting up python3-defusedxml (0.7.1-2) ... 352s Setting up python3-ipython-genutils (0.2.0-6) ... 352s Setting up python3-asttokens (2.4.1-1) ... 352s Setting up fonts-glyphicons-halflings (1.009~3.4.1+dfsg-3) ... 352s Setting up python3-all (3.12.3-0ubuntu1) ... 352s Setting up python3-coverage (7.4.4+dfsg1-0ubuntu2) ... 352s Setting up libjs-moment (2.29.4+ds-1) ... 352s Setting up python3-pandocfilters (1.5.1-1) ... 352s Setting up libjs-requirejs (2.3.6+ds+~2.1.37-1) ... 352s Setting up libjs-es6-promise (4.2.8-12) ... 352s Setting up libjs-text-encoding (0.7.0-5) ... 352s Setting up python3-webencodings (0.5.1-5) ... 352s Setting up python3-platformdirs (4.2.1-1) ... 353s Setting up python3-psutil (5.9.8-2build2) ... 353s Setting up libsource-highlight-common (3.1.9-4.3build1) ... 353s Setting up python3-jupyterlab-pygments (0.2.2-3) ... 353s Setting up libpython3.12t64:arm64 (3.12.4-1) ... 353s Setting up libpgm-5.3-0t64:arm64 (5.3.128~dfsg-2.1build1) ... 353s Setting up python3-decorator (5.1.1-5) ... 353s Setting up python3-packaging (24.0-1) ... 353s Setting up python3-wcwidth (0.2.5+dfsg1-1.1ubuntu1) ... 353s Setting up node-jed (1.1.1-4) ... 353s Setting up python3-typeshed (0.0~git20231111.6764465-3) ... 353s Setting up python3-executing (2.0.1-0.1) ... 354s Setting up libjs-xterm (5.3.0-2) ... 354s Setting up python3-nest-asyncio (1.5.4-1) ... 354s Setting up python3-bytecode (0.15.1-3) ... 354s Setting up libjs-codemirror (5.65.0+~cs5.83.9-3) ... 354s Setting up libjs-jed (1.1.1-4) ... 354s Setting up python3-html5lib (1.1-6) ... 354s Setting up libbabeltrace1:arm64 (1.5.11-3build3) ... 354s Setting up python3-fastjsonschema (2.19.1-1) ... 354s Setting up python3-traitlets (5.14.3-1) ... 354s Setting up python-tinycss2-common (1.3.0-1) ... 354s Setting up python3-argon2 (21.1.0-2build1) ... 354s Setting up python3-dateutil (2.9.0-2) ... 355s Setting up libjs-jquery (3.6.1+dfsg+~3.5.14-1) ... 355s Setting up python3-mistune (3.0.2-1) ... 355s Setting up python3-stack-data (0.6.3-1) ... 355s Setting up python3-soupsieve (2.5-1) ... 355s Setting up fonts-font-awesome (5.0.10+really4.7.0~dfsg-4.1) ... 355s Setting up python3-jupyter-core (5.3.2-2) ... 355s Setting up libjs-bootstrap (3.4.1+dfsg-3) ... 355s Setting up libjs-underscore (1.13.4~dfsg+~1.11.4-3) ... 355s Setting up python3-ptyprocess (0.7.0-5) ... 355s Setting up libjs-marked (4.2.3+ds+~4.0.7-3) ... 355s Setting up python3-prompt-toolkit (3.0.46-1) ... 356s Setting up libdebuginfod1t64:arm64 (0.191-1) ... 356s Setting up python3-tinycss2 (1.3.0-1) ... 356s Setting up libzmq5:arm64 (4.3.5-1build2) ... 356s Setting up python3-jedi (0.19.1+ds1-1) ... 356s Setting up libjs-bootstrap-tour (0.12.0+dfsg-5) ... 356s Setting up libjs-backbone (1.4.1~dfsg+~1.4.15-3) ... 356s Setting up libsource-highlight4t64:arm64 (3.1.9-4.3build1) ... 356s Setting up python3-nbformat (5.9.1-1) ... 356s Setting up python3-bs4 (4.12.3-1) ... 357s Setting up python3-bleach (6.1.0-2) ... 357s Setting up python3-matplotlib-inline (0.1.6-2) ... 357s Setting up python3-comm (0.2.1-1) ... 357s Setting up python3-prometheus-client (0.19.0+ds1-1) ... 357s Setting up gdb (15.0.50.20240403-0ubuntu1) ... 357s Setting up libjs-jquery-ui (1.13.2+dfsg-1) ... 357s Setting up python3-pexpect (4.9-2) ... 357s Setting up python3-zmq (24.0.1-5build1) ... 358s Setting up python3-terminado (0.18.1-1) ... 358s Setting up python3-jupyter-client (7.4.9-2ubuntu1) ... 358s Setting up python3-pydevd (2.10.0+ds-10ubuntu1) ... 358s Setting up python3-debugpy (1.8.0+ds-4ubuntu4) ... 359s Setting up python3-nbclient (0.8.0-1) ... 359s Setting up python3-ipython (8.20.0-1ubuntu1) ... 359s Setting up python3-ipykernel (6.29.3-1ubuntu1) ... 359s Setting up python3-nbconvert (7.16.4-1) ... 360s Setting up python3-notebook (6.4.12-2.2ubuntu1) ... 360s Setting up autopkgtest-satdep (0) ... 360s Processing triggers for man-db (2.12.1-2) ... 361s Processing triggers for libc-bin (2.39-0ubuntu9) ... 366s (Reading database ... 94675 files and directories currently installed.) 366s Removing autopkgtest-satdep (0) ... 368s autopkgtest [11:43:21]: test autodep8-python3: set -e ; for py in $(py3versions -r 2>/dev/null) ; do cd "$AUTOPKGTEST_TMP" ; echo "Testing with $py:" ; $py -c "import notebook; print(notebook)" ; done 368s autopkgtest [11:43:21]: test autodep8-python3: [----------------------- 368s Testing with python3.12: 369s 369s autopkgtest [11:43:22]: test autodep8-python3: -----------------------] 369s autopkgtest [11:43:22]: test autodep8-python3: - - - - - - - - - - results - - - - - - - - - - 369s autodep8-python3 PASS (superficial) 370s autopkgtest [11:43:23]: @@@@@@@@@@@@@@@@@@@@ summary 370s pytest FAIL non-zero exit status 1 370s command1 PASS (superficial) 370s autodep8-python3 PASS (superficial) 381s nova [W] Skipping flock in bos03-arm64 381s Creating nova instance adt-oracular-arm64-jupyter-notebook-20240616-102219-juju-7f2275-prod-proposed-migration-environment-2-3fa41470-9ba7-4314-bf5b-5890bf50c62a from image adt/ubuntu-oracular-arm64-server-20240616.img (UUID 29c79ba3-a1da-4fc8-887a-16767871ab81)... 381s nova [W] Skipping flock in bos03-arm64 381s Creating nova instance adt-oracular-arm64-jupyter-notebook-20240616-102219-juju-7f2275-prod-proposed-migration-environment-2-3fa41470-9ba7-4314-bf5b-5890bf50c62a from image adt/ubuntu-oracular-arm64-server-20240616.img (UUID 29c79ba3-a1da-4fc8-887a-16767871ab81)... 381s nova [W] Skipping flock in bos03-arm64 381s Creating nova instance adt-oracular-arm64-jupyter-notebook-20240616-102219-juju-7f2275-prod-proposed-migration-environment-2-3fa41470-9ba7-4314-bf5b-5890bf50c62a from image adt/ubuntu-oracular-arm64-server-20240616.img (UUID 29c79ba3-a1da-4fc8-887a-16767871ab81)...